HI, I am using adword webapp flow and show statics of adword,if user connect with my application. When i generate refresh token from console and put into adsapi_php.ini and run GetCampaign.php it return all campaign but if i get refresh token dynamically it give me error like " 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" }" my sample code is
$oauth2 = new OAuth2([ 'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth', 'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token', 'redirectUri' => 'MY_REDIRECT_URL', 'clientId' => 'CLIENT_ID', 'clientSecret' => 'CLIENT_SECRET', 'scope' => 'https://www.googleapis.com/auth/adwords' ]); $callbackUrl = "Call_back_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 /* Generate user ini file to store refresh token for future use. /* $content .= '[ADWORDS]'; $content .= 'developerToken = "DEVELOPER TOKEN"'; $content .= 'clientCustomerId = "'.$customerId.'"'; $content .= '[OAUTH2]'; $content .= 'clientId = "653473292288-mpfqsod96ou57972f0ecscoqqp2cv18b.apps.googleusercontent.com"'; $content .= 'clientSecret = "G6BrjmRgUoajrDe4EQV381sZ"'; $content .= 'refreshToken = "'.$refreshToken.'"'; $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/google/nw.ini","wb"); fwrite($fp,$content); fclose($fp); This ini file is unique for every user and i want to store all information here. My developer token is also approved. After generating ini and run GetCampaign.php file it show above error.Please help me. Thanks, Bezoar Developer -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ 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/f207a369-0271-4b58-96fe-6c0f098b0a4e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.