我有谷歌登录在我的网站上工作,使用 codeigniter-oauth2 除了在最后一步,我收到的只是:
-
access_token
-
到期
仅此而已!
这是我请求数据的地方:
$url = 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&' .
http_build_query(array('access_token' => $token->access_token,));
它执行完整的循环,但是当我签出时:
file_get_contents($url)
我什么也得不到!
这些是我的作用域:
-
https://www.googleapis.com/auth/userinfo.profile
-
https://www.googleapis.com/auth/userinfo.email
-
https://www.googleapis.com/auth/plus.profile.emails.read
我是否缺少示波器?还是我请求的信息不正确?
另外,我正在使用v1
,我应该改用v2
吗?
您的作用域看起来不正确。尝试:
- "https://www.googleapis.com/auth/plus.login"
或
- "个人资料"
接下来,应确保访问令牌有效。可以使用 tokeninfo 终结点检查访问令牌,这将告诉你令牌颁发给谁等信息。
最后,正如@daimto建议的那样,您可能应该从Google+ PHP示例开始,这将为您设置一个客户端库,这使得对Google进行API调用和使用Google的OAuth 2实现变得更加容易。
由于我的服务器不支持IPv6,我最终做的是使用Google的Javascript API。我只是按照谷歌的教程,它工作得很好。