由于403禁止,因此无法将事件插入Android日历(如何检查我是否可以在日历中书写)

时间:2019-08-26 11:18:54

标签: android permissions calendar id

我想在没有确认弹出窗口的情况下在日历中添加事件。 但是我不知道如何检查我是否可以写在日历中。

只有具有读/写权限的日历才可以实际修改。但是如何检查这些日历?

我选择了日历的随机ID,因为用户具有不同的日历。这是我的代码的示例:

// You need to name the keys as you desire. (I can't figure out the labels by the type_id and status numbers).
$statusPair = collect([
    'performance and deleted' => [
        'type_id' => 1,
        'status'  => 0,
    ],
    'something'               => [
        'type_id' => 1,
        'status'  => 1,
    ],
    'something 2'             => [
        'type_id' => 2,
        'status'  => 0,
    ],
    'something 3'             => [
        'type_id' => 2,
        'status'  => 1,
    ],
]);

$data = $users->map(function ($user) use ($statusPair) {
    $receipts = $user->receipts;

    $sums = $statusPair->mapWithKeys(function ($pair, $statusLabel) use ($receipts) {
        $filtered = $receipts;
        foreach ($pair as $key => $value) {
            $filtered = $filtered->where($key, $value);
        }
        $sum = $filtered->sum('amount');

        return [
            $statusLabel => $sum,
        ];
    });

    return [
        'id'       => $user->id,
        'name'     => $user->name,
        'receipts' => $sums->toArray(),
    ];
});

我收到此错误:

int calendarId = ????

ContentResolver contentResolver = this.getContentResolver();
ContentValues calEvent = new ContentValues();
calEvent.put(CalendarContract.Events.CALENDAR_ID, calendarId);
Uri uri = contentResolver.insert(CalendarContract.Events.CONTENT_URI,
calEvent);

我在AndroidManifest.xml中添加了权限

2019-08-26 13:07:26.902 24886-25416/? E/EventHandler: Can't insert event into xxxxxxxxxxxxxxxxxxxxxxxx@import.calendar.google.com: Forbidden
    com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
    {
      "errors": [
        {
          "reason": "requiredAccessLevel",
          "domain": "calendar",
          "message": "You need to have writer access to this calendar."
        }
      ],
      "message": "You need to have writer access to this calendar.",
      "code": 403
    }
        at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
        at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
        at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
        at com.google.android.syncadapters.calendar.Utils.executeAndLog(Utils.java:555)
        at com.google.android.syncadapters.calendar.EventHandler.sendEntityToServer(EventHandler.java:409)
        at com.google.android.syncadapters.calendar.CalendarSyncAdapterApiary.sendEntityToServer(CalendarSyncAdapterApiary.java:3689)
        at com.google.android.syncadapters.calendar.CalendarSyncAdapterApiary.processLocalChanges(CalendarSyncAdapterApiary.java:3628)
        at com.google.android.syncadapters.calendar.CalendarSyncAdapterApiary.processLocalChangesForHandler(CalendarSyncAdapterApiary.java:3548)
        at com.google.android.syncadapters.calendar.CalendarSyncAdapterApiary.performSync(CalendarSyncAdapterApiary.java:658)
        at com.google.android.syncadapters.calendar.CalendarSyncAdapterApiary.onPerformLoggedSync(CalendarSyncAdapterApiary.java:440)
        at com.android.emailcommon.syncadapter.LoggingThreadedSyncAdapter.onPerformSync(LoggingThreadedSyncAdapter.java:49)
        at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:334)

谢谢。

0 个答案:

没有答案