使用JSON更新谷歌的Contacts API

时间:2022-12-19 14:53:14

With the Google Contacts API, you can GET contact information using JSON, but is there a way to update it using JSON? I haven't had any success in my attempts, and continue to get a "content not allowed in prolog" error when I try (seemingly indicating that they're expecting XML in the PUT request).

使用谷歌Contacts API,您可以使用JSON获得联系信息,但是有办法使用JSON更新它吗?我的尝试没有取得任何成功,并且在尝试时继续获得“prolog中不允许的内容”错误(似乎表明他们希望在PUT请求中使用XML)。

On the GET request, I GET from following URL: http://www.google.com/m8/feeds/contacts/user@gmail.com/full?alt=json

在GET请求中,我从以下URL获得:http://www.google.com/m8/feeds/contacts/user@gmail.com/full.com/?

When I want to update a contact using XML I PUT to the following type of URL (it varies based on which contact is being updated): http://www.google.com/m8/feeds/contacts/user@gmail.com/base/0

当我想使用XML更新联系人时,我将其放到以下类型的URL(根据更新联系人的类型不同):http://www.google.com/m8/feeds/contacts/user@gmail.com/base/0

I've tried adding alt=json onto the PUT request, but that was just a shot in the dark since I haven't found any actual documentation to confirm updating using JSON is even possible. I'm doing this interaction in JS from a firefox addon, so that's why my preference is to use JSON (I've been working with E4X up until this point and find it to be pretty janky).

我尝试过在PUT请求中添加alt=json,但这只是一个尝试,因为我还没有找到任何实际的文档来确认使用json进行更新甚至是可能的。我使用firefox addon的JS进行这种交互,所以我更喜欢使用JSON(我一直在使用E4X,直到现在,我发现它很简练)。

Any help would be greatly appreciated!

如有任何帮助,我们将不胜感激!

1 个解决方案

#1


5  

I see no traces about "update google contact using JSON in PUT".

我没有看到关于“在PUT中使用JSON更新谷歌联系人”的踪迹。

Google dev guide says:

谷歌开发指南说:

To update an existing contact, first retrieve the entry you want to update, modify it, and then send a PUT request with the updated entry in the message body to the contact's edit URL. Use the application/atom+xml content type

要更新现有的联系人,首先检索您想要更新的条目,修改它,然后发送一个PUT请求,将消息正文中的更新条目发送到联系人的编辑URL。使用应用程序/atom+xml内容类型

(from http://code.google.com/apis/contacts/docs/3.0/developers_guide_protocol.html#Updating )

(来自http://code.google.com/apis/contacts/docs/3.0/developers_guide_protocol.html更新)

#1


5  

I see no traces about "update google contact using JSON in PUT".

我没有看到关于“在PUT中使用JSON更新谷歌联系人”的踪迹。

Google dev guide says:

谷歌开发指南说:

To update an existing contact, first retrieve the entry you want to update, modify it, and then send a PUT request with the updated entry in the message body to the contact's edit URL. Use the application/atom+xml content type

要更新现有的联系人,首先检索您想要更新的条目,修改它,然后发送一个PUT请求,将消息正文中的更新条目发送到联系人的编辑URL。使用应用程序/atom+xml内容类型

(from http://code.google.com/apis/contacts/docs/3.0/developers_guide_protocol.html#Updating )

(来自http://code.google.com/apis/contacts/docs/3.0/developers_guide_protocol.html更新)