【问题标题】:XMLHttpRequest cannot load https://www.googleapis.com/drive/v3/files due to access control checks由于访问控制检查,XMLHttpRequest 无法加载 https://www.googleapis.com/drive/v3/files
【发布时间】:2020-10-08 20:18:43
【问题描述】:

我正在使用带有电容器的 ionic 并尝试使用 google drive api 从目录中提取列表文件。我能够在 android 上提取文件列表,但是当我尝试在 ios 上运行(同时使用模拟器和设备)时,它给了我这个错误。

这是我用来访问该 URI 的代码。请注意,我正在使用服务帐户来验证我的请求。

drive(access_token): Observable<Object> {
const headers = new HttpHeaders({
  'Content-Type': 'application/json',
  'Authorization': 'Bearer ' + access_token
})

return this.http.get("https://www.googleapis.com/drive/v3/files", { headers: headers }).pipe(
  tap(data => data['files']),
  catchError(this.handleError)
);
}

在我的应用程序上,我还使用了 google calendar api,我能够从中提取信息,因此我知道访问令牌是好的。

我也尝试使用邮递员访问 uri,并且能够在那里提取文件列表。 不知道这里有什么问题,对任何输入都很满意。

【问题讨论】:

    标签: ios angularjs ionic-framework google-drive-api capacitor


    【解决方案1】:

    我最终使用了不同的 http 客户端,我最初使用的是 angulars httpClient,但切换到 ionic 本机 http 客户端,我能够访问 google drive 端点。

    https://ionicframework.com/docs/native/http

    【讨论】:

      猜你喜欢
      • 2018-05-29
      • 2020-12-18
      • 1970-01-01
      • 2018-11-12
      • 2020-10-28
      • 1970-01-01
      • 2020-10-18
      • 2017-09-16
      • 2018-03-07
      相关资源
      最近更新 更多