[英]Fatal error: Uncaught Error: Undefined constant “STDIN” in C:\xampp\htdocs\imagebob\google-drive.php:41
when I try to want access the token the verification code is not working and they give me error undefined constant "STDIN" im new here in google API so please help me what's I do?当我试图访问令牌时,验证码不起作用,他们给我错误未定义的常量“STDIN”我在谷歌 API 中是新的,所以请帮我做什么? Thanks谢谢
if ($client->isAccessTokenExpired()) {
// Refresh the token if possible, else fetch a new one.
if ($client->getRefreshToken()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
} 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));
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
$client->setAccessToken($accessToken);
// Check to see if there was an error.
if (array_key_exists('error', $accessToken)) {
throw new Exception(join(', ', $accessToken));
}
}
// Save the token to a file.
if (!file_exists(dirname($tokenPath))) {
mkdir(dirname($tokenPath), 0700, true);
}
file_put_contents($tokenPath, json_encode($client->getAccessToken()));
}
The example code on the quickstart tells you use the php
command . 快速入门上的示例代码告诉您使用php
命令。 This means that you are executing it on a console/terminal where you have STDIN
.这意味着您正在拥有STDIN
的控制台/终端上执行它。
If you are trying to do a web server application, you don't have it and thus the code is different.如果您尝试做一个 web 服务器应用程序,您没有它,因此代码是不同的。 You can find the most common setups on the library's GitHub repository ( see examples ).您可以在库的 GitHub 存储库中找到最常见的设置(参见示例)。 Take a look to them, understand their differences, and choose the one that's best for you.看看他们,了解他们的差异,然后选择最适合您的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.