I’m having trouble on reading my inbox in gmail using Oauth 2.0. I’m using this as my scope : https://mail.google.com/mail/feed/atom/
This is my non-working code
$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);
I even get my access token but still no luck, get an Unauthorize 401 error.
https://mail.google.com/mail/feed/atom/ is not a scope its the server endpoint from where you can get the feed. See the doc. Here is a working code in Vb.net
Using PHP and Client Login
I am not sure how to do this using OAuth2.0 or even if its possible to get feed using OAuth 2.0 at all.