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.

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

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler