如何使用Google Contact API和.NET更新单个联系人的群组成员资格?

时间:2023-01-17 14:21:01

I want to retrieve a specific contact, and update its group membership. I already know the self link of the contact. To get the specific contact, the developer's guide says to do this:

我想检索特定联系人,并更新其组成员身份。我已经知道联系人的自我链接了。要获得具体联系,开发人员指南要说:

//The example assumes the ContactRequest object (cr) is already set up.

//该示例假定已设置ContactRequest对象(cr)。

Contact c = cr.Retrieve<Contact>("http://www.google.com/m8/feeds/contacts/liz%40gmail.com/full/12345");

but when I compile this, I get an error:

但是当我编译它时,我收到一个错误:

Argument 1: cannot convert from 'string' to 'Google.Contacts.Contact'

参数1:无法从'string'转换为'Google.Contacts.Contact'

If I change it to:

如果我将其更改为:

Contact c = cr.Retrieve<Contact>(new Uri("http://www.google.com/m8/feeds/contacts/liz%40gmail.com/full/12345"));

then it compiles, and seems to retrieve okay, but I'm unable to update the contact's group membership:

然后它编译,似乎检索没问题,但我无法更新联系人的组成员身份:

c.GroupMembership.Add(member2);
cr.Update(c);

as the cr.Update(c) line throws a GDataRequestException (400 Bad Request) with a response string of:

因为cr.Update(c)行抛出一个GDataRequestException(400 Bad Request),响应字符串为:

"Group membership information not supported"

“不支持组成员资格信息”

What am I doing wrong?

我究竟做错了什么?

1 个解决方案

#1


2  

I figured out what I was doing wrong...

我弄清楚我做错了什么......

When retrieving the contact, I was using the "Id" property, instead of the "Self" property.

检索联系人时,我使用的是“Id”属性,而不是“Self”属性。

The "Id" property has "base" projection, while the "Self" property has "Full" projection.

“Id”属性具有“基础”投影,而“自”属性具有“完全”投影。

Once I switched to using "Self" it worked properly.

一旦我切换到使用“Self”,它就能正常工作。

#1


2  

I figured out what I was doing wrong...

我弄清楚我做错了什么......

When retrieving the contact, I was using the "Id" property, instead of the "Self" property.

检索联系人时,我使用的是“Id”属性,而不是“Self”属性。

The "Id" property has "base" projection, while the "Self" property has "Full" projection.

“Id”属性具有“基础”投影,而“自”属性具有“完全”投影。

Once I switched to using "Self" it worked properly.

一旦我切换到使用“Self”,它就能正常工作。