Google 通讯录数据 API 给出 500 错误
我正在使用 OAUTH2 身份验证导入 GMAIL 联系人。在我的代码中,我将配置参数存储在一个数组中:
$clientid=<my Client id>;
$clientsecret=<my client secret>;
$redirecturi=<my redirect URL>;
$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 as $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>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>
但对于所有后续回调 ,我正在获取正确的访问令牌。
第一次出了什么问题?
更新 我以某种方式重置了我的客户端密码,并且有一段时间,我得到了正确的 XML 响应。但是,突然之间,它开始给我一个新的错误。
在curl调用获取access_token之后,它显示了{“error”:“invalid_grant”}。为什么会这样呢?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的
$auth_code
已被使用,您将收到invalid_grant
错误。授权码只能使用一次。You will get the
invalid_grant
error if your$auth_code
was already used. Authorization codes can only be used once.