我再次跟踪本教程,使用php直接从我的REMOTE SERVER上传Google文件:所以我从Google API控制台创建了新的API项目,启用了Drive API服务,请求了OAuth客户端ID和客户端密钥,并在脚本,然后将其与Google API Client Library for PHP文件夹一起上传到此http://www.MYSERVER.com/script1.php,以检索验证码:
<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
$drive = new Google_Client();
$drive->setClientId('XXX'); // HERE I WRITE MY Client ID
$drive->setClientSecret('XXX'); // HERE I WRITE MY Client Secret
$drive->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$drive->setScopes(array('https://www.googleapis.com/auth/drive'));
$gdrive = new Google_DriveService($drive);
$url = $drive->createAuthUrl();
$authorizationCode = trim(fgets(STDIN));
$token = $drive->authenticate($authorizationCode);
?>
Run Code Online (Sandbox Code Playgroud)
当我访问http://www.MYSERVER.com/script1.php时, 我允许授权并获取我可以在第二个脚本中编写的Auth代码.然后我将其上传到http://www.MYSERVER.com/script2.php,看起来像:
<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
$drive = new Google_Client();
$drive->setClientId('X'); // HERE I WRITE MY Client ID …Run Code Online (Sandbox Code Playgroud)