Как правильно загрузить файл на Google Диск через Curl PHPPhp

Кемеровские программисты php общаются здесь
Anonymous
Как правильно загрузить файл на Google Диск через Curl PHP

Сообщение Anonymous »

Я пытаюсь загрузить файлы на Google Диск с помощью Curl в PHP, используя этот пример API: API загрузки файлов на Google Диск.
Вот моя проблема:
Когда я запускаю приведенный ниже код. Я получил успешное сообщение, как показано ниже, но в эту папку не загружен ни один файл.
Вот ответ Google API

Код: Выделить всё

string(121) "{ "kind": "drive#file", "id": "171bgh8-nDojxGjd_Fxxxxxxx", "name": "Untitled", "mimeType": "image/png" } "
Вот код

Код: Выделить всё

$file_path = 'baby.png';
$folder_id = 'id of the folder goes here'; // ID of the folder you want to upload to

$mimetype=  mime_content_type($file_path);
$filename=  basename($file_path);

$headers = array(
"Authorization: Bearer $access_token",
"Content-Type: $mimetype"
);

$post_fields = json_encode(array(
'name' => basename($file_path),
'parents' => array($folder_id),
'metadata' => "{name :$filename};type=application/json;charset=UTF-8",
'file' => new CURLFile($file_path, $mimetype),
));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart');
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);
$response = curl_exec($ch);
curl_close($ch);

var_dump($response);
Как мне загрузить файл в эту папку по идентификатору папки?

Подробнее здесь: https://stackoverflow.com/questions/786 ... a-curl-php

Вернуться в «Php»