【发布时间】:2015-03-30 18:32:06
【问题描述】:
我正在从我的服务器上的这个页面获取 google api 授权代码
https://github.com/google/google-api-php-client/blob/master/examples/user-example.php
在我的主机上测试同一页面
http://mawk3y.net/google/google-api-php-client/examples/user-example.php
在调整客户端 ID、秘密和重定向 uri 之后。
$data =file_get_contents('https://accounts.google.com/o/oauth2/auth?code='.$code.'&client_secret={secret}&redirect_uri={my web page}&grant_type=authorization_code');
print_r($data);
但我收到一个错误,所以我在从该页面获取授权码后尝试将完整的 url 粘贴到浏览器地址栏(与我从该页面获得的相同身份验证码 https://developers.google.com/oauthplayground/)
https://accounts.google.com/o/oauth2/token?code={authorization code}&redirect_uri=mywebpage.php&client_id={my client id}&client_secret={secret code}&grant_type=authorization_code
但结果是
{
"error" : "invalid_request"
}
如何解决这个问题并用授权码交换访问令牌
【问题讨论】:
标签: php google-api authorization access-token