【问题标题】:google drive sdk/google drive api ----using PHP web applicationgoogle drive sdk/google drive api ----使用PHP web应用
【发布时间】:2015-02-11 23:13:04
【问题描述】:

我正在使用 Google drive API 创建网站页面,它执行以下操作:--

提供存储在我的 Google 驱动器中的用户组 pdf 文件,无需通过任何方式进行任何类型的登录/身份验证,并且文件是公开的。 谁访问了该页面,如果他/她想下载该文件/pdf,那么他/她只需单击它即可完成,无需任何注册和登录。

我不知道如何开始使用它...是否有必要使用 OAuth 2...

简单来说,我想使用谷歌驱动器作为文件托管站点来托管我的文件并通过网站接触用户。 请给我您宝贵的解决方案... 谢谢

【问题讨论】:

  • 您使用的是什么编程语言或平台?

标签: oauth-2.0 google-drive-api


【解决方案1】:

对于 php,请查看 here 以获取完整示例和视频。您必须为您使用的编程语言下载 Google Drive API。然后使用该 API 来帮助您验证和访问文件。这是一个使用 PHP 的 Google 开发者页面示例

<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';

$client = new Google_Client();
// Get your credentials from the console
$client->setClientId('YOUR_CLIENT_ID');
$client->setClientSecret('YOUR_CLIENT_SECRET');
$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);
?>

【讨论】:

    【解决方案2】:

    您将需要使用位于此处的 PHP 客户端库:https://developers.google.com/api-client-library/php/

    然后,您需要使用 auth2 对 google 进行身份验证。

    然后您可以使用 PHP 客户端库调用 Drive API https://developers.google.com/drive/v2/reference/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-07
      相关资源
      最近更新 更多