2017-08-21 10 views
0

グッド日、最新のGoogleアドワーズ広告のOAuth APIの実装

私はv201705でより最新のAPIバージョンにアドワーズ広告のAPIのOAuthを移行しようとしている問題を抱えています。

v201609を使用していた私の古い実装は動作しています。このバージョンは夕焼けになっています。私は私のアプリをより新しいAPIバージョンに移行しています。

Googleからのドキュメントや、アドワーズ広告APIの最新バージョンに関連するアドワーズ広告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']; 

感謝を:以下

は私が現時点で実現しようとしているが、明らかにこれは動作していないおよび/または完全に何かが欠けているものです。

+0

:以下

は、私が出ていると、今取り組んでいるものです。 –

答えて

0

Googleアドワーズ実装を以前使用していたので、Google OAuth2の実装に従う必要があることがわかりました。両方が同じように動作することは分かっていませんでした。私はこの1つを把握するために管理している

$redirectUri = 'http://xxxxxxx/dashboard/accounts/oauth2callback'; 
    $code = $_GET['code']; 

    $oauth2 = new OAuth2([ 
     'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth', 
     'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token', 
     'redirectUri' => $redirectUri, 
     'clientId' => $this->client_id, 
     'clientSecret' => $this->client_secret, 
     'scope' => '****' 
    ]); 


    $oauth2->setCode($code); 
    $authToken = $oauth2->fetchAuthToken(); 

    // Store the refresh token for your user in your local storage if you 
    // requested offline access. 
    $refreshToken = $authToken['refresh_token']; 
関連する問題