React native 如何访问用户';谷歌日历来自React Native(世博会)?

React native 如何访问用户';谷歌日历来自React Native(世博会)?,react-native,google-calendar-api,expo,React Native,Google Calendar Api,Expo,我使用Expo,我想向拥有Google帐户的用户添加对我的应用程序的访问权限。然后我需要获得登录到我的应用程序的用户的谷歌日历信息 我使用:Expo.Google.logInAsync(选项)()实现登录功能。我的范围如下所示: scopes: ['https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https

我使用Expo,我想向拥有Google帐户的用户添加对我的应用程序的访问权限。然后我需要获得登录到我的应用程序的用户的谷歌日历信息

我使用:
Expo.Google.logInAsync(选项)
()实现登录功能。我的范围如下所示:

scopes: ['https://www.googleapis.com/auth/userinfo.email',
         'https://www.googleapis.com/auth/userinfo.profile',
         'https://www.googleapis.com/auth/calendar.readonly']
getUsersCalendarList = async (accessToken) => {
    let calendarsList = await fetch('https://www.googleapis.com/calenda/v3/users/me/calendarList', {
    headers: { Authorization: `Bearer ${accessToken}`},
    });
    return calendarsList.json();
}
当有人试图登录我的应用程序时,它会询问是否有权查看日历列表。作为回应,我得到:

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",
    },
}
我收到了关于该用户的数据,但没有关于其日历的任何数据。 我尝试使用此函数获取有关日历()的数据:

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日历列表?

您还可以在请求中添加访问令牌作为参数

https://www.googleapis.com/calenda/v3/users/me/calendarList?access_token={token}
我不是react开发者,所以不确定如何修复你的标题。看起来不错。

我在这里找到了解决方案:。需要对返回的对象使用
json()
函数。
getUsersCalendarList
schulde如下所示:

scopes: ['https://www.googleapis.com/auth/userinfo.email',
         'https://www.googleapis.com/auth/userinfo.profile',
         'https://www.googleapis.com/auth/calendar.readonly']
getUsersCalendarList = async (accessToken) => {
    let calendarsList = await fetch('https://www.googleapis.com/calenda/v3/users/me/calendarList', {
    headers: { Authorization: `Bearer ${accessToken}`},
    });
    return calendarsList.json();
}

请编辑您的问题并包含完整的错误消息。我添加了完整的错误消息。我不确定获取用户日历信息的流程是否正确。你知道它到底是怎么工作的吗?我可以通过
accessToken
从任何google帐户或仅从应用程序帐户获取有关用户日历的信息吗?我如何检查它是否在react native之外工作?我试图从浏览器中执行此URL(使用真实令牌),但我得到了“未找到”。然后您的访问令牌出现问题,可能会过期,只有一小时有效。你可以在这里测试它,但你不能提供你的访问令牌@DalmTo我的访问令牌如下:
ya29.GluUBkIgKjUdNVAteJqDd3YMGj\u pHztwosIK6dLnHgLYUWm\u 2SJy5ql\u AyqaOHhE-Len\u EsDt1wiORY25SdV4WjH5c0w4yl-zet5thcnpeafo4qwny7uitwjgya
它有什么问题吗?它可能过期了。它可能是一个刷新令牌,也可能是一个授权码。尝试并生成一个新的。