To exchange an authorization code for an access token, call the https://oauth2.googleapis.com/token endpoint and set the following parameters:
NodeJs - Axios cURL PHP - cURL
Copy var axios = require('axios');
var config = {
method: 'post',
url: 'https://oauth2.googleapis.com/token?redirect_uri=http://localhost:5001/appgregator/us-central1/googleads/callback&client_id=329011709740-sq6l548671df39l5bingat6kpd0rmuth.apps.googleusercontent.com&client_secret=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&grant_type=authorization_code&code=4/0AWgavdeTEPxfXAPtbSUqv2OrbfRPywz7JUhCeZbDV4smVxBOgztU4TzFqNOwC0diUCCPog',
headers: { }
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Copy curl --location --request POST 'https://oauth2.googleapis.com/token?redirect_uri=http://localhost:5001/appgregator/us-central1/googleads/callback&client_id=329011709740-sq6l548671df39l5bingat6kpd0rmuth.apps.googleusercontent.com&client_secret=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&grant_type=authorization_code&code=4/0AWgavdeTEPxfXAPtbSUqv2OrbfRPywz7JUhCeZbDV4smVxBOgztU4TzFqNOwC0diUCCPog'
Copy <?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://oauth2.googleapis.com/token?redirect_uri=http://localhost:5001/appgregator/us-central1/googleads/callback&client_id=329011709740-sq6l548671df39l5bingat6kpd0rmuth.apps.googleusercontent.com&client_secret=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&grant_type=authorization_code&code=4/0AWgavdeTEPxfXAPtbSUqv2OrbfRPywz7JUhCeZbDV4smVxBOgztU4TzFqNOwC0diUCCPog',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;