2
我試圖將文件提交到Google Drive。雖然文件已上傳到驅動器,但遇到接受按鈕後出現錯誤。將文件提交給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('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);
?>
錯誤消息:
說明:使用未定義的常量STDIN的 - 假定 'STDIN' 在C:\的LocalServer \ htdocs中\ PDF \ quickstart.php上線18
警告:與fgets()預計參數1是資源,在串C中給出:\的LocalServer \ htdocs中\ PDF \上線quickstart.php 18
如何可以固定
那麼,什麼是'STDIN'和它來自哪裏?我看不到這條線上的任何地方 –
這裏仍然//請求授權 打印「請訪問:\ n $ authUrl \ n \ n」; 打印「請輸入驗證碼:\ n」; $ authCode = trim(fgets(STDIN)); –
我看到了。你的問題是你正在使用一個名爲'STDIN'的常量,它在任何地方都沒有定義。它應該是一個變量,例如'$ STDIN'?沒有看到定義的常量/變量的位置,我們無法幫助您。 –