I'm just getting started with the GMail API and I'm attempting to use AJAX to fetch emails.
This is my code:
$.ajax({
beforeSend: function (request)
{
request.setRequestHeader("authorization", "Bearer xxxxxxxxxxxxxxxxx.apps.googleusercontent.com");
},
url: 'https://www.googleapis.com/gmail/v1/users/me/messages?key=xxxxxxxxxxxxxxxxxx',
dataType: 'json',
cache: false,
success: function(data) {
// this.setState({Emails: data});
console.log("Mail thread"+data);
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
When I make the call, I receive a 401 error. Upon inspecting the request URL, I notice that there's an additional query parameter added to the end of it:
&_=1470236511985
So the final request URL looks like this.
https://www.googleapis.com/gmail/v1/users/me/messages?key=xxxxxxxxxxxxxxxxxx&_=1470236511985
Could this extra query parameter be causing the 401 error, or am I using the authorization header incorrectly? How can I go about fixing this issue?
Thank you in advance.