我有oauth访问令牌,但我的get请求失败。以下是我的代码:
$response = array();
$crl = curl_init();
$newurl = "https://www.googleapis.com/gmail/v1/users/myemail@gmail.com/messages?access_token=" . $result['access_token'];
echo $newurl . "</br>";
curl_setopt($crl, CURLOPT_HTTPGET, true);
curl_setopt($crl, CURLOPT_URL, $newurl);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
$reply = curl_exec($crl);
if ( $reply ) {
echo 'successfully retrieved messages</br>';
echo $reply;
} else {
echo 'failed to get messages</br>'; // prints
echo $reply; // prints nothing
}
我确认我的钥匙是正确的: Does my Google oAuth2 Token look right?
myemail@gmail.com肯定是提供访问权限的人。由于这是PHP,我无法调试,因为我没有控制台(我试图打印出它没有打印的回复)。