douzhang5984 2016-09-28 11:57
浏览 67

PHP Google Adwords:invalid_grant

I have made a request to google adwords and got a refresh token (without using GetRefreshToken.php from the php library). I have copied and pasted the refresh_token, developerToken, client_id and client_secret into the auth.ini file.

But when I run the following part:

$user = new AdWordsUser();

$campaignService = $user->GetService('CampaignService', 'v201603');

// Create selector.
$selector = new Selector();
$selector->fields = array('Id', 'Name');
$selector->ordering[] = new OrderBy('Name', 'ASCENDING');

// Create paging controls.
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

// Make the get request.
$page = $campaignService->get($selector);

In return I get the following error:

 OAuth2Exception in SimpleOAuth2Handler.php line 119:
{
"error" : "invalid_grant"
}

The library is: Library. And the SimpleOAuth2Handler.php is here: Oauth

Any ideas why?

  • 写回答

1条回答 默认 最新

  • duanaigua4033 2016-10-08 21:33
    关注

    Have you tried passing the values directly into the adwords constructor function to make sure they are valid or at least are you setting the customer account number ? . The refresh token is used to obtain an access token which is good for about an hour. Caching this would help performance as you would not need to fetch a new access token every request.

    Try adding the following -

    $user->SetClientCustomerId('set your account number here');
    
    // also if you are sure your oAuth data is valid 
    
    $user->SetOAuth2Info('pass your oauth data')
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)