获取“请求的身份验证范围不足”使用 ionic 5 和 Angular 11 从 Gmail 导入联系人时出现 403 错误代码

问题描述

我正在使用 ionic 5 和 Angular 11。我想从 Gmail 导入联系人并将其显示在离子列表中。 为了获取访问令牌,我使用了 Google-plus 插件。下面是我获取访问令牌代码。获得访问令牌后,我使用 https://developers.google.com/people/api/rest/v1/people.connections/list API 来获取联系人姓名、电话号码和电子邮件地址。

 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)
      }
   }
   

但这给了我 403 错误

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

谁能帮我解决这个问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)