2016-07-31 131 views
1

我想安装验证与谷歌加使用their tutorial。我按照方向逐字,改变了signin.php中的client idclient secret。为了记录,Google开发者控制台中启用了Google plus API。我按照说明更新文件权限(chmod +x signin.phpchmod -R 555 vendor/)。然而,在加载我的身份验证URL(恰好在我的域的auth_test/子目录中,然后单击登录按钮时,控制台会抛出401 (unauthorized),发送get请求/activites.我已经研究了该问题,并且看到这可能是由无效的令牌造成的,但我没有看到怎么说可能是因为一切都已经设置在singin.php.太大的帮助,将不胜感激......谷歌加OAuth PHP 401(未授权)

+0

你确定你可以做一个curl请求?....也许你没有curl扩展启用。 – Hackerman

回答

1

您需要重置您的应用程序的状态,如果断开刷新$tocken

Google API office处理API错误的文档

401: Invalid Credentials 

授权标头无效。您使用的访问令牌为 已过期或无效。

{ "error": { 
>  "errors": [ 
>  { 
>   "domain": "global", 
>   "reason": "authError", 
>   "message": "Invalid Credentials", 
>   "locationType": "header", 
>   "location": "Authorization", 
>  } 
>  ], 
>  "code": 401, 
>  "message": "Invalid Credentials" } } 

建议的操作:刷新使用长寿命 刷新令牌的访问令牌。如果失败,如授权您的应用程序

而且它显然是在singin.php注释行没有说明通过OAuth的流程, 引导用户。 98:

// Normally the state would be a one-time use token, however in our 
    // simple case, we want a user to be able to connect and disconnect 
    // without reloading the page. Thus, for demonstration, we don't 
    // implement this best practice. 
    //$app['session']->set('state', ''); 

因此,在你的情况看来,您的应用程序是断开,从而导致$token变空。因此强制这个代码块在行号:91

if (empty($token)) { 
     // Ensure that this is no request forgery going on, and that the user 
     // sending us this connect request is the user that was supposed to. 
     if ($request->get('state') != ($app['session']->get('state'))) { 
      return new Response('Invalid state parameter', 401); 
     }