Google CardDAV API 403 Error

2019-08-07 18:36发布

I've been trying to use Google's CardDAV APIs (and I've successfully gotten CalDAV access working). Unfortunately, I keep getting a 403 error when trying to discover the user's current-user-principal. FWIW, I have gone to Google's Developer Console and set up client information and it seems to work perfectly fine for CalDAV access.

Here is a snippet of the HTTP traffic for CardDAV:

PROPFIND https://www.googleapis.com:443/.well-known/carddav/
Depth: 0
Content-Type: text/xml
Brief: T
Authorization: Bearer ya29.1.AADtN_UD1CVKpIQPsyB4HzoKVxt4L5kPFXU3GucMTfJmJj9t0pzZqX1i3Xx748Y
<?xml version="1.0" encoding="utf-8"?>
<x0:propfind xmlns:x0="DAV:">
  <x0:prop>
    <x0:current-user-principal />
    <x0:principal-URL />
    <x0:resourcetype />
  </x0:prop>
</x0:propfind>

vvvvvvvvvvvv

HTTP PROPFIND Status(403) Forbidden
<?xml version="1.0" encoding="UTF-8"?>
<errors xmlns="http://schemas.google.com/g/2005">
 <error>
  <domain>GData</domain>
  <code>insufficientPermissions</code>
  <internalReason>Insufficient Permission</internalReason>
 </error>
</errors>

If anyone has some insight as to why this might be happening, it would be greatly appreciated.

Red

2条回答
姐就是有狂的资本
2楼-- · 2019-08-07 18:48

You need to request access for Google Carddav API, i.e. https://www.googleapis.com/auth/carddav

I fear that still might not be enough rights, because even with that permission (and also the permission for https://www.googleapis.com/auth/contacts) I get empty reports for my addressbook. That's very strange. Even after putting a contact with my client.

查看更多
在下西门庆
3楼-- · 2019-08-07 18:50

I have been playing around with this today and succeeded just now. I am using two oauth scopes

https://www.googleapis.com/auth/carddav

https://www.google.com/m8/feeds

I was getting a 403 when just using the second one. I then do a depth 1 propfind on getetag and then a multiget to get the vcards. The response is super speedy.

p.s. With the URL you are using you will also get an http-redirect

查看更多
登录 后发表回答