I am using ionic 5 and Angular 11. I want to import contacts from Gmail and display it in a ion-list. To get the access token I am using Google-plus plugin .Below is my code to get the access token. After getting access token I am using https://developers.google.com/people/api/rest/v1/people.connections/list API to get the contacts name, phonenumber and emailAddresses.

 import { GooglePlus } from '@ionic-native/google-plus/ngx';
  import { HttpClient, HttpHeaders } from '@angular/common/http';
      
  constructor(private googlePlus: GooglePlus, private http: HttpClient) { }
  
   getContactFromGmail() {
     const param = {
      'scopes': 'https://www.googleapis.com/auth/contacts.readonly', 
      'webClientId': My webClientId, 
      'offline': true 
      };
      
    this.googlePlus.login({ param })
      .then(res => {
        console.log(res);
        if (res) {
          let accessToken = res.accessToken;
          const httpOptions = {
            headers: new HttpHeaders({
              'Accept': 'application/json',
              'Authorization': `Bearer ${accessToken}`
            })
          };
          var url = 'https://people.googleapis.com/v1/people/me/connections?personFields=names,emailAddresses,phoneNumbers&key=My_API_KEY'
          console.log(url)

         this.http.get(url, httpOptions);
        }


      }).catch(err => {
        console.error(err)
      }
   }
   

But this is giving me 403 error.

{
  "error": {
    "code": 403,
    "message": "Request had insufficient authentication scopes.",
    "status": "PERMISSION_DENIED"
  }
}

Can anybody please help me how to solve this.

0

There are 0 best solutions below