My Company has a Google Application that we use for connecting to various Google APIs (Youtube, DFA... etc) via OAuth. Today I am trying to integrate Adwords into this application and am only getting the error "invalid_grant". I have looked through the "Enabled APIs" and see no way to enable Adwords to an application specifically. I suspect that is done through the developer token. The user's token is new created after we were granted permission to use the API in a production environment. Our application type is a "Web Application" type. and when we create tokens we create them for use Offline. I also made sure to add the users's adwords ID to the manager account so the developer key has access to the user's adwords account.
This is the code snippet I am using. It is pretty much straight out of the example documentation, with minor mods to get oauth creds from the configuration file.
Can someone please point me in the right direction.
protected function getCustomer($account, $params)
{
try {
// Retrieve the client_id and client_secret
$config = $this->container->getParameter('google_app');
// Get dev_token and user_agent
$adwords = $this->container->getParameter('google_adwords');
// oauth 2 config
$oauth2Info = array(
'client_id' => $config['id'],
'client_secret' => $config['secret'],
'refresh_token' => $params['refresh_token']
);
$user = new \AdWordsUser(null, $adwords['dev_token'], $adwords['user_agent'], null, null, $oauth2Info);
// Get the adwords customer
$customerService = $user->GetService("CustomerService");
$customer = $customerService->get();
$customerInfoArray = array();
$customerService = $user->GetService("CustomerService");
$customer = $customerService->get();
print_r($customer);
exit();
// return $customer;
} catch (OAuth2Exception $e) {
throw new \Exception("ERROR_OAUTH_AUTHORIZATION_FAILURE", 500);
} catch (ValidationException $e) {
throw new \Exception("ERROR_OAUTH_AUTHORIZATION_FAILURE", 500);
} catch (Exception $e) {
throw new \Exception("ERROR_UNEXPECTED_FAILURE", 500);
}
}