Hello Adword Team,

I want to use webapp flow for get all users info when they visit my site. 
When i use Console for generating refresh token GetCampaign return all 
campaign but after generate refresh token using outh from browser it gives 
me error Uncaught exception 'GuzzleHttp\Exception\ClientException' with 
message 'Client error: `POST https://www.googleapis.com/oauth2/v4/token` 
resulted in a `401 Unauthorized` response: { "error": 
"unauthorized_client", "error_description": "Unauthorized" }


Please help me to built application. My code is 

$oauth2 = new OAuth2([
    'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth',
    'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',
    'redirectUri' => 'REDIRECT_URL',
    'clientId' => 'CLIENT_ID',
    'clientSecret' => 'CLIENT_SECRET',
    'scope' => 'https://www.googleapis.com/auth/adwords'
]);
$callbackUrl = "CALLBACK_URL";
if (!isset($_GET['code'])) {

  $oauth2->setState(sha1(openssl_random_pseudo_bytes(1024)));
  $_SESSION['oauth2state'] = $oauth2->getState();

  $config = [
    // Set to 'offline' if you require offline access.
    'access_type' => 'offline',    
    'approval_prompt'=>'force'


  ];
  header('Location: ' . $oauth2->buildFullAuthorizationUri($config));
  exit;
} elseif (empty($_GET['state']) || ($_GET['state'] !== 
$_SESSION['oauth2state'])) {    

  unset($_SESSION['oauth2state']);
  exit('Invalid state.');
} else {
  
 $oauth2->setCode($_GET['code']);
 $authToken = $oauth2->fetchAuthToken();
echo '<pre>';
print_r($authToken);die;
  $refreshToken = $authToken['refresh_token'];

     $session = (new AdWordsSessionBuilder())
        ->fromFile('adsapi_php.ini')
        ->withOAuth2Credential($oauth2)
        ->build();
    /* ------------------------- Session build 
---------------------------------------------*/


    /* -------------------------------- Adwords Services section 
----------------------------*/

    /* Creating object of Adwords services */
    $adWordsServices = new AdWordsServices();

    /* Adwords Customer services */
    $customerService = $adWordsServices->get($session, 
CustomerService::class);
     $customers = $customerService->getCustomers();
    $customerId = $customers[0]->getCustomerId();  // Getting main customer 
client id 


$content .= '[ADWORDS]';
$content .= 'developerToken = "DEVELOPER_TOKEN"';
$content .= 'clientCustomerId = "'.$customerId.'"';

$content .= '[OAUTH2]';

$content .= 'clientId = "CLIENT_ID';
$content .= 'clientSecret = "CLIENT_SECRET"';
$content .= 'refreshToken = "'.$refreshToken.'"';


$fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/google/nw.ini","wb");
fwrite($fp,$content);
fclose($fp);

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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/b702b60a-4cdd-454d-a243-58574c69158e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • unauthor... Bezoar Software
    • Re:... 'Sreelakshmi Sasidharan (AdWords API Team)' via AdWords API Forum

Reply via email to