【问题标题】:Google API PHP: Uncaught Exception on createAuthURL()?Google API PHP:createAuthURL() 上的未捕获异常?
【发布时间】:2014-08-19 07:49:37
【问题描述】:

我刚刚下载了最新的 Google API PHP,我正在尝试使用“使用 Google 登录”脚本。 API 抛出了这个显然未被捕获的异常:

致命错误:带有消息的未捕获异常“Google_Auth_Exception” '未指定范围' /home/rlcoachi/public_html/hidden/googlelogin/src/Google/Client.php:178 堆栈跟踪:#0 /home/rlcoachi/public_html/hidden/googlelogin/src/Google/Client.php(237): Google_Client->prepareScopes() #1 /home/rlcoachi/public_html/hidden/googlelogin/api.php(76): Google_Client->createAuthUrl() #2 {main} 抛出 /home/rlcoachi/public_html/hidden/googlelogin/src/Google/Client.php on 第 178 行

我的api.php 脚本的第 74-77 行是:

else 
{
    //For Guest user, get google login url
    $authUrl = $gClient->createAuthUrl();
}

gClient 是一个使用 id、secret、url、key 设置的 Google_Client 对象

Full script is available here

【问题讨论】:

    标签: php google-api-php-client


    【解决方案1】:

    转到名为 googlelogin/src/Google/Client.php 的文件

    搜索

    protected $scopes = array();
    

    然后用

    之类的范围填充数组
    protected $scopes = array("userinfo.email", "userinfo.profile");
    

    如果您想获取用户 emailId 以及个人资料详细信息...

    【讨论】:

      【解决方案2】:

      尝试:

      $client->setScopes(array(
           'https://www.googleapis.com/auth/plus.login',
           'profile',
           'email',
           'openid',
      ));
      

      【讨论】:

      • 请编辑您的答案以添加对您的代码如何工作以及它如何解决 OP 问题的解释。很多 SO 发帖人都是新手,看不懂你贴的代码。
      猜你喜欢
      • 1970-01-01
      • 2018-10-12
      • 2017-12-30
      • 1970-01-01
      • 2017-03-30
      • 2020-08-04
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多