【发布时间】:2017-08-21 02:24:48
【问题描述】:
美好的一天,
我在尝试将我的 adwords API oAuth 迁移到更新的 API 版本(即 v201705)时遇到问题。
我使用 v201609 的旧实现正在运行,现在因为这个版本已经处于日落状态。我一直在将我的应用迁移到更新的 API 版本。
基本上,我很难从 Google 或任何地方找到任何说明如何使用与最新 Adwords API 版本相关的 Adwords API 实施 Google oAuth 的文档。
以下是我当前的代码:
$redirectUri = 'http://xxxxxxx/dashboard/accounts/oauth2callback';
$code = $_GET['code'];
//$code = Request::query('code');
$user = new AdWordsUser(
base_path('auth.ini'),
null,
null,
null,
base_path('settings.ini'),
null
);
$OAuth2Handler = $user->GetOAuth2Handler();
// Get the access token using the authorization code. Ensure you use the same
// redirect URL used when requesting authorization.
$user->SetOAuth2Info(
$OAuth2Handler->GetAccessToken(
$user->GetOAuth2Info(), $code, $redirectUri));
// The access token expires but the refresh token obtained for offline use
// doesn't, and should be stored for later use.
//return $user->GetOAuth2Info();
//$result = json_decode($user->GetOAuth2Info());
$refreshToken = $user->GetOAuth2Info()['refresh_token'];
谁能指出我最新的 Google Adwords API 版本的正确实现?
以下是我目前一直在努力实现的目标,但显然这不起作用和/或完全遗漏了一些东西:
$redirectUri = 'http://xxxxxxx/dashboard/accounts/oauth2callback';
$code = $_GET['code'];
//$code = Request::query('code');
/* $user = new AdWordsUser(
base_path('auth.ini'),
null,
null,
null,
base_path('settings.ini'),
null
); */
// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())
->fromFile()
->build();
// Construct an API session configured from a properties file and the OAuth2
// credentials above.
$user = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();
$OAuth2Handler = $user->GetOAuth2Handler();
// Get the access token using the authorization code. Ensure you use the same
// redirect URL used when requesting authorization.
$user->SetOAuth2Info(
$OAuth2Handler->GetAccessToken(
$user->GetOAuth2Info(), $code, $redirectUri));
// The access token expires but the refresh token obtained for offline use
// doesn't, and should be stored for later use.
//return $user->GetOAuth2Info();
//$result = json_decode($user->GetOAuth2Info());
$refreshToken = $user->GetOAuth2Info()['refresh_token'];
$customer_id = $this->GetClientCustomerName($refreshToken)['customer_id'];
//$customer_name = $this->GetClientCustomerName($refreshToken)['customer_name'];
谢谢。
【问题讨论】:
-
我已经设法弄清楚了这一点。
标签: php laravel laravel-5 google-oauth google-ads-api