I'm trying to fetch the emails from the logged in user. Using https://www.googleapis.com/gmail/v1/users/userId/messages. I'm passing access_token, scope as a header in my AJAX call. But i'm getting
"errors": [{ "domain": "global", "reason": "authError", "message": "Invalid Credentials", "locationType": "header", "location": "Authorization" }], "code": 401, "message": "Invalid Credentials" } }
This is my component in which i'm trying to fetch mails
componentDidMount() {
> const user_mail_id = localStorage.getItem('user_mail_id');
> const access_token = localStorage.getItem('access_token');
> console.log(access_token);
> var config = {
> headers: {
> 'Authorization': "BEARER " + access_token,
> "Accept": "application/json",
> "scope": "https://mail.google.com/
https://www.googleapis.com/auth/gmail.modify
> https://www.googleapis.com/auth/gmail.readonly"
> },
> }
> // console.log(user_mail_id);
> axios.get('https://www.googleapis.com/gmail/v1/users/' +
> user_mail_id
> + '/messages/', config)
> .then(function (response) {
> console.log(response);
> })
> .catch(function (error) {
> console.log(error);
> });`enter code here`
> }