作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图将文件提交到 Google Drive。虽然文件已上传到驱动器,但在点击接受按钮后出现错误。
<?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('http://localhost/pdf/quickstart.php');
$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);
?>
错误信息:
Notice: Use of undefined constant STDIN - assumed 'STDIN' in C:\LocalServer\htdocs\pdf\quickstart.php on line 18
Warning: fgets() expects parameter 1 to be resource, string given in C:\LocalServer\htdocs\pdf\quickstart.php on line 18
最佳答案
STDIN 是一个命令行指令,它不是一个直接有效的 php 语句..
我所做的是:
$client = new Google_Client();
// Get your credentials from the console
$client->setClientId('**********************');
$client->setClientSecret('*********');
$client->setRedirectUri('*********');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
$authUrl = $client->createAuthUrl();
print $authurl
$authCode = ''; // insert the verification code that you get after going to url in $authurl
file_put_contents('token.json', $client->authenticate($authCode));
$service = new Google_DriveService($client);
$client->setAccessToken(file_get_contents('token.json'));
//Insert a file
..... // rest the same
关于php - 将文件提交到 Google Drive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20183954/
我是一名优秀的程序员,十分优秀!