duankui6150 2015-12-22 20:24
浏览 45
已采纳

Google Adwords API。 如何使用PHP库刷新令牌

Let me start here. The Google Adwords API does not work with the standard Google API Oauth method. It has it's own. Please do not respond with using that library or it's methods it is different.

OK, over the last couple days I have been integrating the GoogleAdwords API OAuth method code into my companies code. I can get an access and refresh token from the server with no issue. The access tokens are good for 1 hours and then need to be refreshed.

// oauth 2 config
$credentials= array(
    'client_id' => $config['id'],
    'client_secret' => $config['secret'],
    'access_token' => $params['access_token'],
    'refresh_token' => $params['refresh_token']
);

$user = new \AdWordsUser(null, $adwords['dev_token'],
    $adwords['useragent'], null, null, $credentials);

The above code works properly with a brand new token. If I take the $user object and try to get CustomerService object from the API I can get the data back. However after an hour the token goes bad and I am no longer able to use it.

I have searched Google's Adwords API Forum (via Google Groups), and also a general Google search. The only code I have been able to find is this code.

$client = $user->GetOAuth2Handler();
$credentials = $client->RefreshAccessToken($user->GetOAuth2Info());
$user->SetOAuth2Info($credentials);

But when I add it I always get this error.

{ "error" : "unauthorized_client" }

I am at a complete loss...

Also please not I do not use an auth.ini we use our own config files and add the parameters to the api objects.

  • 写回答

1条回答 默认 最新

  • doula2426 2015-12-23 03:28
    关注
    { "error" : "unauthorized_client" }
    

    This error means that a different google application client_id was specified. We use multiple google apps and I had copied and pasted some code forgetting that for Adwords we are using a new app, where other google APIs we integrate are all using the same app.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?