【问题标题】:Fatal error: Uncaught Error: Undefined constant "STDIN" in C:\xampp\htdocs\imagebob\google-drive.php:41致命错误:未捕获的错误:C:\xampp\htdocs\imagebob\google-drive.php:41 中未定义的常量“STDIN”
【发布时间】: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


【解决方案1】:

The example code on the quickstart tells you use the php command。这意味着您在拥有STDIN 的控制台/终端上执行它。

如果您尝试做一个 Web 服务器应用程序,您没有它,因此代码是不同的。您可以在库的 GitHub 存储库 (see examples) 上找到最常见的设置。看看他们,了解他们的差异,然后选择最适合您的。

【讨论】:

    猜你喜欢
    • 2021-10-20
    • 2016-09-19
    • 2015-08-24
    • 2017-08-24
    • 2019-02-25
    • 2022-09-28
    • 2019-07-09
    • 2022-12-14
    • 1970-01-01
    相关资源
    最近更新 更多