【问题标题】:Google oAuth - Invalid_grant, Got refresh_token but no app accessGoogle oAuth - Invalid_grant,获得 refresh_token 但无应用访问权限
【发布时间】:2015-07-20 03:25:46
【问题描述】:

我需要你的帮助:

我正在使用 Google AdWords API PHP 库并将其集成到 Symfony2 中。我生成了获取 Refresh_token 的 URL,它似乎工作正常,我收到了刷新令牌。但每次我想访问 API 时都会收到“invalid_grant”错误。

我检查了我的 gMail-Test 帐户,但找不到我的应用程序。

这就是我所做的:

我生成了 Access-URL,它工作正常:

https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=4160XXXXX-7j6qpXXXXXXXXXXXXkctXXX.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%2F%2Fadcheck%2Fweb%2Fapp_dev.php%2Fapp%2Ftoken%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords&access_type=offline&approval_prompt=force

我点击它并接受它,以便我的“AdWords Web”应用可以访问和管理我的 Google AdWords 帐户。

Google 然后将我重定向到我的 Redirect_uri 并发送 refresh_token:

http://localhost/adcheck/web/app_dev.php/app/token/?code=4/ughxxxxxxxxxxxxxxxxxxxxxxxxxIZeF5yoMzI#

但“AdWords 网络”应用未连接。我在我的 Google Account Apps 列表中找不到它,尽管我得到了成功的答案和刷新令牌。

有人可以帮忙吗?我很无奈,找不到什么问题:/

【问题讨论】:

    标签: oauth google-ads-api


    【解决方案1】:

    好的,我找到了! Google 不会返回刷新令牌。 Google 返回一个 Access_token,然后可用于生成 refresh_token。

     $AdWordsUser->SetOAuth2Info(
            $OAuth2Handler->GetAccessToken(
                $AdWordsUser->GetOAuth2Info(), $code, $redirectUri));
    $AdWordsUser->SetRefreshToken($AdWordsUser->GetOAuth2Info('refresh_token'));
    

    Google 使用 $redirectUri 生成的 Access_token

    $code = $this->get('request')get->('code');
    

    当您第一次尝试通过访问令牌获取 refresh_token 时,Google 会将其添加到您个人 Google 帐户的“我的应用程序”站点中。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 2017-02-11
      • 2017-09-18
      • 1970-01-01
      相关资源
      最近更新 更多