【发布时间】:2021-05-21 02:21:14
【问题描述】:
当我尝试访问令牌时,验证码不起作用,他们给我错误未定义常量“STDIN”,我在谷歌 API 中是新的,所以请帮我做什么?谢谢
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()));
}
【问题讨论】:
-
STDIN仅在从 CLI 而非网络服务器运行脚本时可用。你是如何运行这个脚本的? -
我该如何解决这个错误,我的项目你能帮我解决这个问题吗?
-
如果您从网页运行脚本,您可以使用
$_POST或$_GET获取参数,具体取决于表单的提交方式。 -
任何关于PHP处理表单的教程都会解释这一点。
-
先生,当我使用 $_POST 或 $_GET 时,他们给了我这种类型的错误“致命错误:未捕获的错误:数组回调必须在 C:\xampp\htdocs\imagebob\google 中有两个元素-drive.php:41 堆栈跟踪:#0 C:\xampp\htdocs\imagebob\google-drive.php(62): getClient() #1 {main} 在 C:\xampp\htdocs\imagebob\google- 中抛出drive.php 在第 41 行"
标签: php google-api google-drive-api stdin