因此,基本上google開發人員的文檔不會更新以匹配其新版本的api。Google Drive PHP api,將文件插入驅動器
這裏是我的代碼:
<?php
require_once 'autoload.php';
$client = new Google_Client();
// Get your credentials from the console
$client->setClientId ('CLIENT_ID');
$client->setClientSecret ('CLIENT_SECRET');
$client->setRedirectUri ('urn:ietf:wg:oauth:2.0:oob');
$client->setScopes (array (
'https://www.googleapis.com/auth/drive'
));
$service = new Google_Service ($client);
$authUrl = $client->createAuthUrl();
// Request authorization
print "Please visit:\n$authUrl\n\n";
print "Please enter the auth code:\n";
$authCode = trim (fgets (STDIN));
// Exchange authorization code for access token
$accessToken = $client->authenticate ($authCode);
$client->setAccessToken ($accessToken);
// Insert a file
$file = new Google_Service_Drive_DriveFile();
$file->setTitle ('My document');
$file->setDescription ('A test document');
$file->setMimeType ('text/plain');
$data = file_get_contents ('document.txt');
$createdFile = $service->files->insert ($file, array (
'data' => $data,
'mimeType' => 'text/plain'
));
echo $createdFile;
?>
這是錯誤我得到:
PHP Notice: Undefined property: Google_Service::$files in D:\DATA\java\php workspace\Google Drive api test\quickstart.php on line 34
PHP Fatal error: Call to a member function insert() on a non-object in D:\DATA\java\php workspace\Google Drive api test\quickstart.php on line 34
這是有問題的代碼行:
$createdFile = $service->files->insert
如果您有任何想法,如果我應該進口一些其他類或東西,請告知。謝謝。