Google Contacts data API giving 500 Error

偶尔善良 提交于 2019-12-02 12:35:14

问题


I am using OAUTH2 authentication to import GMAIL contacts . In my code I am storing the config parameters in an array :

$clientid=<my Client id>;
$clientsecret=<my client secret>;
$redirecturi=<my redirect URL>;
$max_results = 25;

Below is how I create the POST array :

$fields=array(
    'code'=>  urlencode($auth_code),
    'client_id'=>  urlencode($clientid),
    'client_secret'=>  urlencode($clientsecret),
    'redirect_uri'=>  urlencode($redirecturi),
    'grant_type'=>  urlencode('authorization_code')
);

$post = '';
foreach($fields as $key=>$value) { $post .= $key.'='.$value.'&'; }
$post = rtrim($post,'&');

Now I'm making a CURL call to get the access token :

$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,'https://accounts.google.com/o/oauth2/token');
curl_setopt($curl,CURLOPT_POST,5);
curl_setopt($curl,CURLOPT_POSTFIELDS,$post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
$result = curl_exec($curl);
curl_close($curl);              


$response =  json_decode($result);
$accesstoken = $response->access_token;
log_message('debug','POST'.$post);
log_message('debug','contents'.$result);

Here is where I am having trouble. For the first callback , this request access token process return a Error 500 response which is displayed in my logs as follows :

<HTML>
<HEAD>
<TITLE>Error processing OAuth 2 request</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Error processing OAuth 2 request</H1>
<H2>Error 500</H2>
</BODY>
</HTML>

But for all subsequent callbacks, I am getting the proper access token .

What's going wrong for the first time ?

Update I somehow did reset my client-secret , and for a time , I got the proper XML response . But , suddenly , out of the blues ,it has started giving me a new error .

Just after the curl call to get the access_token , it shows me {"error":"invalid_grant"}. Why this is so ?


回答1:


You will get the invalid_grant error if your $auth_code was already used. Authorization codes can only be used once.



来源:https://stackoverflow.com/questions/7396426/google-contacts-data-api-giving-500-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!