【问题标题】:Google Calendar API Insert Event using Android使用 Android 的 Google Calendar API 插入事件
【发布时间】:2016-05-21 06:46:20
【问题描述】:

我已关注https://developers.google.com/google-apps/calendar/v3/reference/events/insert#examples 插入一个新事件,但我在这一行遇到问题:

event = service.events().insert(calendarId, event).execute();

当我调试到上述行时,应用程序强制关闭并且我不知道问题...

【问题讨论】:

  • 你能从 Logcat 发布你的堆栈跟踪吗?
  • 这是我发现的原因:com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden { "code" : 403, "errors" : [ { "domain" : "global" , "message" : "Insufficient Permission", "reason" : "insufficientPermissions" } ], "message" : "Insufficient Permissions" }
  • 您需要在插入事件之前进行身份验证
  • 请告诉我如何进行身份验证,我是 Auth 新手 ..

标签: android calendar google-api google-calendar-api


【解决方案1】:

在我的情况下,问题也是范围,所以对于那些不知道如何解决的人来说,解决方案是:

改变这个

private static final String[] SCOPES = { CalendarScopes.CALENDAR_READONLY };

为此

private static final String[] SCOPES = { CalendarScopes.CALENDAR };

现在您可以初始化凭据了

// Initialize credentials and service object.
        mCredential = GoogleAccountCredential.usingOAuth2(
                getApplicationContext(), Arrays.asList(SCOPES))
                .setBackOff(new ExponentialBackOff());

【讨论】:

    【解决方案2】:

    请告诉我如何进行身份验证,我是 Auth 新手

    要使用日历 API 进行身份验证,您需要在 GDC 中启用日历 API。之后,您需要为 Android 生成 OAuthClientID。您还将定义一个范围,无论您是想读、写还是两者兼而有之。这是完整的Setup Process

    完成 oAuth 设置后,您将成为 adding several dependencies in your Android Project

    试试full sample

    【讨论】:

    • 感谢您的回答!这对我很有用,我在范围上有错误。
    • @JuT.Jun 很高兴我能帮上忙。赞成或接受答案即可。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    相关资源
    最近更新 更多