首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安装教程是否已过时?Google API新手在这里

安装教程是否已过时?Google API新手在这里
EN

Stack Overflow用户
提问于 2015-02-15 11:28:49
回答 1查看 61关注 0票数 1

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,我只是想上传文件,有人能帮我吗?我遗漏了什么?

代码语言:javascript
复制
 <?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);
?>
EN

回答 1

Stack Overflow用户

发布于 2015-02-16 13:22:29

所以我找到了这个:Submitting file to Google drive

代码确实过时了,我做了以下更改:

代码语言:javascript
复制
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.

这应该能起到作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28522730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档