0
votes

I have made a request to google adwords and got a refresh token (without using GetRefreshToken.php from the php library). I have copied and pasted the refresh_token, developerToken, client_id and client_secret into the auth.ini file.

But when I run the following part:

$user = new AdWordsUser();

$campaignService = $user->GetService('CampaignService', 'v201603');

// Create selector.
$selector = new Selector();
$selector->fields = array('Id', 'Name');
$selector->ordering[] = new OrderBy('Name', 'ASCENDING');

// Create paging controls.
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

// Make the get request.
$page = $campaignService->get($selector);

In return I get the following error:

 OAuth2Exception in SimpleOAuth2Handler.php line 119:
{
"error" : "invalid_grant"
}

The library is: Library. And the SimpleOAuth2Handler.php is here: Oauth

Any ideas why?

1

1 Answers

0
votes

Have you tried passing the values directly into the adwords constructor function to make sure they are valid or at least are you setting the customer account number ? . The refresh token is used to obtain an access token which is good for about an hour. Caching this would help performance as you would not need to fetch a new access token every request.

Try adding the following -

$user->SetClientCustomerId('set your account number here');

// also if you are sure your oAuth data is valid 

$user->SetOAuth2Info('pass your oauth data')