https://developers.google.com/drive/web/quickstart/quickstart-php#step_3_set_up_the_sample
尝试运行quickstart.php文件时,我发现它完全没有任何作用。检查代码并将其与我的文件进行比较,我发现文件夹和文件名不同。我从github下载了这个库,我还注意到src文件夹在两天前更新了。
我试着改变它们使快速入门运行,但它什么也不起作用。
我正在尝试授权google drive从页面上传文件。我已经得到了我的密钥和id,hello world和所有这些步骤,我只是不能让快速入门运行。
我不知道怎么使用subversion,我只是想上传文件,有人能帮我吗?我遗漏了什么?
<?php
require_once 'google-api-php-client/src/Google_Client.php'; //incorrect files
require_once 'google-api-php-client/src/contrib/Google_DriveService.php'; /incorrect files
$client = new Google_Client();
// Get your credentials from the console
$client->setClientId('already changed');
$client->setClientSecret('already changed');
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
$service = new Google_DriveService($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_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',
));
print_r($createdFile);
?>发布于 2015-02-16 13:22:29
所以我找到了这个:Submitting file to Google drive
代码确实过时了,我做了以下更改:
require_once 'google-api-php-client/src/Google/Client.php';
require_once 'google-api-php-client/src/contrib/Google/Service.php';
instead of Google_DriveService just use Google_Service.
implement the code posted by user3407337 on the previous link.这应该能起到作用。
https://stackoverflow.com/questions/28522730
复制相似问题