Invalid_request OAuth2 Google?

时间:2016-12-19 12:05:16

标签: curl oauth-2.0 google-oauth google-oauth2

我收到了代码:4/sfPsZXlH-eO4kqj8EE8WDO70jEMn3HyMuk7ZvjkqL-Q#

尝试获取访问令牌在URL上执行请求后:

$authUrl = "https://accounts.google.com/o/oauth2/token";

curl_setopt_array($curl, array(
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => array(
        'code' => $code,
        'client_id' => CLIENT_ID,
        'client_secret' => CLIENT_SECRET,
        'redirect_uri' => getRedirectUri(),
        'grant_type' => 'authorization_code'
    ),
    CURLOPT_URL => $authUrl,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_RETURNTRANSFER => true
));

但是得到错误:

object(stdClass)#1 (1) {
  ["error"]=>
  string(15) "invalid_request"
}

如何检测出错?

1 个答案:

答案 0 :(得分:0)

尝试打印上面的请求。但我看不到AuthCode被传递到令牌网址以获取访问令牌。您可以验证上面的过程 google oauth playground也是。 https://developers.google.com/oauthplayground/

相关问题