Oauth 2.0 google drive sdk/google drive api----使用PHP web应用程序

Oauth 2.0 google drive sdk/google drive api----使用PHP web应用程序,oauth-2.0,google-drive-api,Oauth 2.0,Google Drive Api,我正在使用Google drive API创建网站页面,该API执行以下操作:-- 提供用户设置的pdf文件,该文件存储在我的Google drive中,无需通过任何方式进行任何类型的登录/身份验证,并且文件是公开的。 谁访问了该页面,如果他/她想下载该文件/pdf,那么他/她只需点击该页面即可下载,无需注册和登录 我不知道如何开始使用它…是否有必要使用OAuth 2 简单地说,我想使用谷歌驱动器作为文件托管网站来托管我的文件,并通过网站联系到用户。 请给我你有价值的解决方案。。。 感谢php,

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

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

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

简单地说,我想使用谷歌驱动器作为文件托管网站来托管我的文件,并通过网站联系到用户。 请给我你有价值的解决方案。。。 感谢php,请查看完整的示例和视频。您必须下载您正在使用的编程语言的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);
?>

您需要使用位于以下位置的PHP客户端库:

然后,您将希望使用auth2对google进行身份验证


然后,您可以使用PHP客户端库调用驱动API。

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