Google Contacts数据API提供500错误 [英] Google Contacts data API giving 500 Error

查看:172
本文介绍了Google Contacts数据API提供500错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用OAUTH2身份验证来导入GMAIL联系人。在我的代码中,我将配置参数存储在数组中:

  $ clientid =< my Client id>; 
$ clientsecret =<我的客户秘密>;
$ redirecturi =<我的重定向网址>;
$ max_results = 25;

以下是我如何创建POST数组:

  $ 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为$ key => $ value){$ post。= $ key。'='。$ value。'&'; }
$ post = rtrim($ post,'&');

现在我正在调用 CURL 来获取访问令牌:

  $ 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);

这是我遇到麻烦的地方。
对于第一个回调,此请求访问令牌进程返回一个错误500 响应,该响应显示在我的日志中,如下所示:

 < HTML> 
< HEAD>
< TITLE>处理OAuth 2请求时发生错误< / TITLE>
< / HEAD>
< BODY BGCOLOR =#FFFFFFTEXT =#000000>
< H1>处理OAuth 2请求时出错< / H1>
< H2>错误500< / H2>
< / BODY>
< / HTML>

但是对于所有后续的回调,我正在获取正确的访问令牌。



第一次出现什么问题?

更新我的客户秘密,一段时间后,我得到了正确的XML响应。但突然间,蓝调中,它开始给我一个新的错误。



在curl调用 access_token 之后,它显示我{错误:invalid_grant}。为什么这样呢?

解决方案

如果您获得 invalid_grant 您的 $ auth_code 已被使用。授权码只能使用一次。


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 ?

解决方案

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

这篇关于Google Contacts数据API提供500错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆