RE: get access token - error 302

91 views
Skip to first unread message
Message has been deleted
Message has been deleted
Message has been deleted

Google Ads API Forum Advisor

unread,
Jun 22, 2021, 1:23:59 AM6/22/21
to adwor...@googlegroups.com
Hi,

Thank you for reaching out to our API support team.

Since you mentioned you are using the REST API, you may refer to this REST interface authentication guide for the complete steps that you need to follow in order to acquire the required credentials and successfully authenticate your requests. Also, this section discusses how you can generate a new access token for use in your API calls.

Best regards,

Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


ref:_00D1U1174p._5004Q2Iwqi6:ref

Google Ads API Forum Advisor

unread,
Jun 22, 2021, 6:17:36 AM6/22/21
to adwor...@googlegroups.com
Hi,

I also had to delete your initial post as it contained your client ID. I am reposting the rest of your post instead for reference :

"Hello 
Please forgive me in advance for my English The Google Ads API client library uses gRPC. However, my hosting provider does not give the option to install gRPC. So I have to use the REST API. I am trying to get an access token using the following code:

$url = "https://accounts.google.com/o/oauth2/auth";
$arr = array(
'grant_type' => 'refresh_token', 
'refresh_token' => '***refreshtoken***', 
'client_id' => '***clientid***',
'client_secret' => '***clientsecret***',
);
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
);
$post_arr=array();
foreach ($arr as $key=>$value) {
$post_arr[]=$key."=".$value;
}
$data=implode('&',$post_arr);

$handle=curl_init();
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$response=curl_exec($handle);
$code=curl_getinfo($handle, CURLINFO_HTTP_CODE);

In response I get error 302 and the following


<HTML>
<HEAD>
<TITLE>Moved Temporarily</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Moved Temporarily</H1>
The document has moved <A HREF=XXXXXXXXX>here</A>.
</BODY>
</HTML>


What is my mistake?"
Reply all
Reply to author
Forward
0 new messages