Я пытаюсь написать небольшой script, чтобы загрузить локальный файл на Google Диск с помощью API-интерфейсов Google Диска. Документация очень плохая, но до сих пор я уверен, что код должен выглядеть следующим образом:
<?php
include_once 'Google/Client.php';
include_once 'Google/Service/Drive.php';
include_once 'Google/Auth/OAuth2.php';
$client = new Google_Client();
$client->setScopes(array('https://www.googleapis.com/auth/drive.file'));
$client->setClientId('dfgdfgdg');
$client->setClientSecret('dfgdfgdf');
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$service = new Google_Service_Drive($client);
$data = file_get_contents("a.jpg");
// create and upload a new Google Drive file, including the data
try
{
//Insert a file
$file = new Google_Service_Drive_DriveFile($client);
$file->setTitle(uniqid().'.jpg');
$file->setMimeType('image/jpeg');
$createdFile = $service->files->insert($file, array(
'data' => $data,
'mimeType' => 'image/jpeg',
'uploadType' => 'media',
));
}
catch (Exception $e)
{
print $e->getMessage();
}
print_r($createdFile);
?>
Проблема в том, что я не могу выполнить право аутентификации (или я делаю что-то еще не так?). Полученная ошибка:
HTTP Error: Unable to connect: 'fopen(compress.zlib://https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart) [function.fopen]: failed to open stream: operation failed'
Вслед за этой ошибкой:
Notice: Undefined variable: createdFile in C:\wamp\www\GoogleAPI\index.php on line 39
Что я делаю неправильно? Можете ли вы предоставить простой рабочий script для загрузки файла на Google Диск с помощью API-интерфейсов Google Диска? Заранее благодарю вас!