Reputation: 1751
I am using the google adwords API to connect with adwords and list all the campaingns. I am connecting with OAuth to the Adwords account and become an access_token and an refresh_token, which I am saving into the DB.
Now I am trying to make this example: https://github.com/googleads/googleads-php-lib/blob/master/examples/AdWords/v201802/BasicOperations/GetCampaigns.php
But my access_token and my refresh_token are in the database and all the API OAuth2 credentials are in one configuration array.
How to query hte google adwords service with this credentials?
Upvotes: 0
Views: 990
Reputation: 171
The OAuth2TokenBuilder class referred to in line 81 of your example and copied below has several methods that'll let you set parameters instead of reading them from the config file.
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
The fromFile method will read parameters from the config file. Your new code might look something like this:
$oAuth2Credential = (new OAuth2TokenBuilder())
->withClientId(your oauth2 client id here)
->withClientSecret(your oauth2 client secret here)
->withRefreshToken(your stored refresh token here)
->build();
High level overview of some other issues with the Google AdWords API here: https://pete-bowen.com/how-to-use-the-google-adwords-api-to-automate-adwords
Upvotes: 1