让我从这里开始。Google Adwords API不适用于标准的Google API Oauth方法。它有它自己的。请不要以使用该库或其方法作为回应——这是不同的。
好吧,在过去的几天里,我一直在将GoogleAdwords API OAuth方法代码集成到我的公司代码中。我可以毫无问题地从服务器获得访问和刷新令牌。访问令牌有效期为1小时,然后需要刷新。
// 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);
上面的代码可以使用全新的令牌正常工作。如果我获取$user
对象并尝试从API获取CustomerService对象,我就可以获取数据。然而,一个小时后,代币坏了,我无法再使用它。
我搜索过Google的Adwords API论坛(通过Google群组),也搜索过一般的Google。我能找到的唯一代码就是这个代码。
$client = $user->GetOAuth2Handler();
$credentials = $client->RefreshAccessToken($user->GetOAuth2Info());
$user->SetOAuth2Info($credentials);
但当我添加它时,我总是会得到这个错误。
{ "error" : "unauthorized_client" }
我完全不知所措。。。
另外,请不要我不使用auth.ini,我们使用自己的配置文件并将参数添加到api对象中。
{ "error" : "unauthorized_client" }
此错误意味着指定了不同的谷歌应用程序client_id。我们使用了多个谷歌应用程序,我复制并粘贴了一些代码,忘记了对于Adwords,我们使用的是一个新的应用程序,而我们集成的其他谷歌API都使用同一个应用程序。