dimanche 20 août 2017

Latest Google Adwords oAuth API implementation

Good Day,

I am having issue trying to migrate my adwords API oAuth to the more recent API version which is v201705.

My old implementation using v201609 is working, and now since this version has been in the sunset. I have been migrating my app to the more recent API version.

Basically I am having a hard time trying to find any documentation from Google or anywhere that shows how to implement Google oAuth with the Adwords API that is relevant to the latest Adwords API versions.

Below is my current code:

$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'];

Can anyone point me to the correct implementation for the latest Google Adwords API version of this?

Below is what I have been trying to achieve at the moment, but obviously this is not working and/or missing something entirely:

$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'];

Thanks.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2v5xKAq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire