c# - 如何创建谷歌联系人?

标签 c#

我正在尝试与谷歌 Gmail 联系人集成 我按照这个例子 Google Contacts API version 3.0我收到此错误请求执行失败:https://www.google.com/m8/feeds/contacts/default/full

Google.Contacts.Contact createdEntry = cr.Insert(feedUri, newEntry);

内心的期待:

{"The remote server returned an error: (400) Bad Request."}

[Line 12, Column 127, element gd:im] Missing attribute: 'address'

完整代码

using Google.Contacts;
using Google.GData.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;



            RequestSettings settings = new RequestSettings("OVI2GoogleContacts", "my email", "pass");
        ContactsRequest cr = new ContactsRequest(settings);

        Google.Contacts.Contact newEntry = new Google.Contacts.Contact();

        // Set the contact's name.
        newEntry.Name = new Name()
            {
                FullName = "Elizabeth Bennet",
                GivenName = "Elizabeth",
                FamilyName = "Bennet",
            };
        newEntry.Content = "Notes";
         //Set the contact's e-mail addresses.
        newEntry.Emails.Add(new EMail()
            {
                Primary = true,
                Rel = ContactsRelationships.IsHome,
                Address = "liz<at>gmail.com"
            });
        newEntry.Emails.Add(new EMail()
            {
                Rel = ContactsRelationships.IsWork,
                Address = "liz<at>example.com"
            });
         //Set the contact's phone numbers.
        newEntry.Phonenumbers.Add(new PhoneNumber()
            {
                Primary = true,
                Rel = ContactsRelationships.IsWork,
                Value = "(206)555-1212",
            });
        newEntry.Phonenumbers.Add(new PhoneNumber()
            {
                Rel = ContactsRelationships.IsHome,
                Value = "(206)555-1213",
            });
        // Set the contact's IM information.
        newEntry.IMs.Add(new IMAddress()
            {
                Primary = true,
                Rel = ContactsRelationships.IsHome,
                Protocol = ContactsProtocols.IsGoogleTalk,
            });
        // Set the contact's postal address.
        newEntry.PostalAddresses.Add(new StructuredPostalAddress()
            {
                Rel = ContactsRelationships.IsWork,
                Primary = true,
                Street = "1600 Amphitheatre Pkwy",
                City = "Mountain View",
                Region = "CA",
                Postcode = "94043",
                Country = "United States",
                FormattedAddress = "1600 Amphitheatre Pkwy Mountain View",
            });
        // Insert the contact.
        Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
        Google.Contacts.Contact createdEntry = cr.Insert(feedUri, newEntry); // here the error

最佳答案

Google 自己的示例代码似乎无效。根据文档 Google Data type/kind gd:im requires the property address to be populated .

@address

@label?

@rel?

@protocol?

@primary?

约定:

elementName Required element

elementName ? Optional element

elementName ***** Optional element, multiple instances allowed

您需要更新部分代码,例如:

newEntry.IMs.Add(new IMAddress()
{
  Address = "email@dot.com",  // untested
  Primary = true,
  Rel = ContactsRelationships.IsHome,
  Protocol = ContactsProtocols.IsGoogleTalk,
});

关于c# - 如何创建谷歌联系人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10364606/

相关文章:

c# - 错误 : No exports were found that match the constraint:

c# - ASP.net AutoMapper 缺少类型映射配置或不支持的映射

c# - 使用 LINQ 插入新的 XML 节点

c# - 将 WinForms 与 XNA 一起使用?

c# - 将背景图像导入/设置到 Windows 窗体导致运行缓慢

c# - 使用 Moq 模拟具体类方法的返回值

c# - 如何从用户控件母版页内的内容页中找到标签控件?

c# - 消除.net lambda 表达式

c# - 将 XML 中的 ebay web 服务响应转换为 C# 对象?

c# - 对 OnMethodBoundaryAspect 中的类属性的引用