我正在尝试通过 Gmails OAuth 2.0 访问用户的邮件,我正在通过 Google 的 OAuth 2.0 Playground 解决这个问题
在这里,他们指定我需要将其作为 HTTP 请求发送:
POST /mail/feed/atom/ HTTP/1.1
Host: mail.google.com
Content-length: 0
Content-type: application/json
Authorization: OAuth SomeHugeOAuthaccess_tokenThatIReceivedAsAString
我尝试编写代码来发送此请求,如下所示:
$crl = curl_init();
$header[] = 'Content-length: 0
Content-type: application/json';
curl_setopt($crl, CURLOPT_HTTPHEADER, $header);
curl_setopt($crl, CURLOPT_POST, true);
curl_setopt($crl, CURLOPT_POSTFIELDS, urlencode($accesstoken));
$rest = curl_exec($crl);
print_r($rest);
不工作,请帮助。:)
更新:我接受了Jason McCreary的建议,现在我的代码如下所示:
$crl = curl_init();
$headr = array();
$headr[] = 'Content-length: 0';
$headr[] = 'Content-type: application/json';
$headr[] = 'Authorization: OAuth '.$accesstoken;
curl_setopt($crl, CURLOPT_HTTPHEADER,$headr);
curl_setopt($crl, CURLOPT_POST,true);
$rest = curl_exec($crl);
curl_close($crl);
print_r($rest);
但我没有得到任何输出。我认为 cURL 在某处默默地失败了。请帮忙。:)
更新 2: NomikOS的伎俩为我做到了。:) :) :) 谢谢!!