【发布时间】:2018-07-19 18:59:22
【问题描述】:
我正在尝试实现PlaylistItems: insertYouTube Data API sample,当我尝试运行它时,我得到以下信息:
注意:使用未定义的常量 STDIN - 在第 51 行的 /example/path/to/script.php 中假定为“STDIN”
包含这一行的函数并没有明确说明 STDIN 从哪里获取它的值:
function getClient() {
$client = new Google_Client();
$client->setApplicationName('API Samples');
$client->setScopes('https://www.googleapis.com/auth/youtube.force-ssl');
// Set to name/location of your client_secrets.json file.
$client->setAuthConfig('client_secrets.json');
$client->setAccessType('offline');
// Load previously authorized credentials from a file.
$credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
if (file_exists($credentialsPath)) {
$accessToken = json_decode(file_get_contents($credentialsPath), true);
} else {
// Request authorization from the user.
$authUrl = $client->createAuthUrl();
printf("Open the following link in your browser:\n%s\n", $authUrl);
print 'Enter verification code: ';
$authCode = trim(fgets(STDIN)); // <--- Appears to be the problem
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
// Store the credentials to disk.
if(!file_exists(dirname($credentialsPath))) {
mkdir(dirname($credentialsPath), 0700, true);
}
file_put_contents($credentialsPath, json_encode($accessToken));
printf("Credentials saved to %s\n", $credentialsPath);
}
$client->setAccessToken($accessToken);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
file_put_contents($credentialsPath, json_encode($client->getAccessToken()));
}
return $client;
}
请原谅我的幼稚,但脚本应该如何提供身份验证代码?为什么不执行这一步?
【问题讨论】:
标签: php google-oauth inputstream stdin