【发布时间】:2019-06-11 13:18:03
【问题描述】:
我使用 Expo,我想向拥有 Google 帐户的用户添加对我的应用程序的访问权限。然后我需要获取登录到我的应用程序的用户的 Google 日历信息。
我使用:Expo.Google.logInAsync(options) (https://docs.expo.io/versions/latest/sdk/google) 实现登录功能。我的范围如下所示:
scopes: ['https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/calendar.readonly']
当有人尝试登录我的应用程序时,它会询问查看日历列表的权限。作为回应,我得到:
Object {
"accessToken": "a",
"idToken": "b",
"refreshToken": "c",
"serverAuthCode": "d",
"type": "success",
"user": Object {
"email": "e",
"familyName": "f",
"givenName": "g",
"id": "h",
"name": "i",
"photoUrl": "j",
},
}
我收到了有关该用户的数据,但没有任何有关其日历的数据。 我尝试使用此函数获取有关日历 (https://developers.google.com/calendar/v3/reference/calendarList) 的数据:
getUsersCalendarList = async (accessToken) => {
let calendarsList = await fetch('https://www.googleapis.com/calenda/v3/users/me/calendarList', {
headers: { Authorization: `Bearer ${accessToken}`},
});
return calendarsList;
}
我得到了回应:
Response {
"_bodyBlob": Blob {
"_data": Object {
"blobId": "67b8b161-690f-4ff6-9cee-1dce12840ebd",
"offset": 0,
"size": 994,
},
},
"_bodyInit": Blob {
"_data": Object {
"blobId": "67b8b161-690f-4ff6-9cee-1dce12840ebd",
"offset": 0,
"size": 994,
},
},
"headers": Headers {
"map": Object {
"alt-svc": Array [
"quic=\":443\"; ma=2592000; v=\"44,43,39,35\"",
],
"cache-control": Array [
"public, max-age=0",
],
"content-type": Array [
"application/json; charset=UTF-8",
],
"date": Array [
"Thu, 17 Jan 2019 11:30:32 GMT",
],
"expires": Array [
"Thu, 17 Jan 2019 11:30:32 GMT",
],
"server": Array [
"GSE",
],
"vary": Array [
"X-Origin",
],
"x-content-type-options": Array [
"nosniff",
],
"x-frame-options": Array [
"SAMEORIGIN",
],
"x-xss-protection": Array [
"1; mode=block",
],
},
},
"ok": false,
"status": 403,
"statusText": undefined,
"type": "default",
"url": "https://www.googleapis.com/calendar/v3/users/me/calendarList",
}
如何在 Expo 中获取用户的谷歌日历列表?
【问题讨论】:
-
请编辑您的问题并包含完整的错误消息。
-
我添加了完整的错误信息。我不确定获取用户日历信息的流程是否正确。你知道它是如何工作的吗?我可以从任何 google 帐户或仅从应用程序帐户使用
accessToken获取有关用户日历的信息吗?
标签: react-native google-calendar-api expo