我在使用Oauth 2.0閱讀Gmail中的收件箱時遇到問題。我用這個作爲我的範圍:https://mail.google.com/mail/feed/atom/Unauthorize 401 Oauth 2.0 google
這是我的非工作代碼
$fields=array(
'code'=> urlencode($authcode),
'client_id'=> urlencode($clientid),
'client_secret'=> urlencode($clientsecret),
'redirect_uri'=> urlencode($redirecturi),
'grant_type'=> urlencode('authorization_code')
);
$fields_string='';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string=rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://accounts.google.com/o/oauth2/token');
curl_setopt($ch,CURLOPT_POST,5);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
$response= json_decode($result);
$accesstoken= $response->access_token;
$xmlresponse= file_get_contents('https://mail.google.com/mail/feed/atom/?oauth_token='.$accesstoken);
我甚至把我的訪問令牌,但仍然沒有運氣,得到一個取消授權401錯誤。
我有同樣的問題。如果你有解決方案。請張貼在這裏。 – Asghar