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);
        }    
    }

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/b358e9ce-d1a6-4585-9da1-a2cc5248fee5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to