I'm trying to access mails of a user through Gmails OAuth 2.0, and I'm figuring this out through Google's OAuth 2.0 Playground
Here, they've specified I need to send this as a HTTP REQUEST:
POST /mail/feed/atom/ HTTP/1.1
Host: mail.google.com
Content-length: 0
Content-type: application/json
Authorization: OAuth SomeHugeOAuthaccess_tokenThatIReceivedAsAString
I've tried writing a code to send this REQUEST like this:
$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);
Not working, please help. :)
UPDATE: I took Jason McCreary's advice and now my code looks like this:
$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);
But I'm not getting any output out of this. I think cURL is silently failing somewhere. Please do help. :)
UPDATE 2: NomikOS's trick did it for me. :) :) :) Thank you!!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…