Я пытаюсь создать разрешение на диск Google в файле через Curl в PHP, но Google Drive API, похоже, выбрасывает ошибки.POST https://www.googleapis.com/drive/v3/fil ... ermissions
{
"requests": [
{
"type": "user",
"role": "commenter",
"emailAddress": "nancyxxxx@gmail.com"
}
]
}
Я попробовал два примера кода ниже
ниже мой пример кода 1.
$access_token = 'xxxxxxxxxxxx';
$file_id ='file id goes here';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/fil ... ermissions");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $access_token",
'Content-Type: application/x-www-form-urlencoded'
]);
//curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"requests\": [\n {\n \"type\": \"anyone\",\n \"role\": \"reader\"\n\n }\n ]\n}");
//curl_setopt($ch, CURLOPT_POSTFIELDS, '{\n "requests": [\n {\n "type": "anyone",\n "role": "reader"\n\n }\n ]\n}');
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"requests\": [\n {\n \"type\": \"anyone\",\n \"role\": \"reader\"\n\n }\n ]\n}");
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
ниже мой пример кода 2.
$access_token = 'xxxxxxxxxxxx';
$file_id ='file id goes here';
$headers = array(
"Authorization: Bearer $access_token",
"Content-Type: application/json"
);
$post_fields = '{
"requests": [
{
"type": "anyone",
"role": "reader"
}
]
}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/fil ... ermissions");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
$response = curl_exec($ch);
var_dump($response);
Вот ошибка.{ "error": { "code": 400, "message": "The permission type field is required.", "errors": [ { "message": "The permission type field is required.", "domain": "global", "reason": "required", "location": "permission.type", "locationType": "other" } ] } } string(323) "{ "error": { "code": 400, "message": "The permission type field is required.", "errors": [ { "message": "The permission type field is required.", "domain": "global", "reason": "required", "location": "permission.type", "locationType": "other" } ] } } "
< /code>
Похоже, что данные запроса разрешения ниже не передаются в API или что API Google Drive Rest имеет некоторые ошибки. Как я могу продолжить? < /P>
{
"requests": [
{
"type": "anyone",
"role": "reader"
}
]
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... g-curl-and
Как правильно создать файлы разрешения на Google Drive REST API с помощью curl и php ⇐ Php
Кемеровские программисты php общаются здесь
1745532773
Anonymous
Я пытаюсь создать разрешение на диск Google в файле через Curl в PHP, но Google Drive API, похоже, выбрасывает ошибки.POST https://www.googleapis.com/drive/v3/files/FILE_ID/permissions
{
"requests": [
{
"type": "user",
"role": "commenter",
"emailAddress": "nancyxxxx@gmail.com"
}
]
}
[b] Я попробовал два примера кода ниже [/b]
[b] ниже мой пример кода 1. [/b]
$access_token = 'xxxxxxxxxxxx';
$file_id ='file id goes here';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/$file_id/permissions");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $access_token",
'Content-Type: application/x-www-form-urlencoded'
]);
//curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"requests\": [\n {\n \"type\": \"anyone\",\n \"role\": \"reader\"\n\n }\n ]\n}");
//curl_setopt($ch, CURLOPT_POSTFIELDS, '{\n "requests": [\n {\n "type": "anyone",\n "role": "reader"\n\n }\n ]\n}');
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"requests\": [\n {\n \"type\": \"anyone\",\n \"role\": \"reader\"\n\n }\n ]\n}");
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
[b] ниже мой пример кода 2. [/b]
$access_token = 'xxxxxxxxxxxx';
$file_id ='file id goes here';
$headers = array(
"Authorization: Bearer $access_token",
"Content-Type: application/json"
);
$post_fields = '{
"requests": [
{
"type": "anyone",
"role": "reader"
}
]
}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/$file_id/permissions");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
$response = curl_exec($ch);
var_dump($response);
Вот ошибка.{ "error": { "code": 400, "message": "The permission type field is required.", "errors": [ { "message": "The permission type field is required.", "domain": "global", "reason": "required", "location": "permission.type", "locationType": "other" } ] } } string(323) "{ "error": { "code": 400, "message": "The permission type field is required.", "errors": [ { "message": "The permission type field is required.", "domain": "global", "reason": "required", "location": "permission.type", "locationType": "other" } ] } } "
< /code>
Похоже, что данные запроса разрешения ниже не передаются в API или что API Google Drive Rest имеет некоторые ошибки. Как я могу продолжить? < /P>
{
"requests": [
{
"type": "anyone",
"role": "reader"
}
]
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78637410/how-to-properly-create-files-permission-on-google-drive-rest-api-using-curl-and[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия