【问题标题】:how to create google contact?如何创建谷歌联系人?
【发布时间】:2013-06-06 12:49:03
【问题描述】:

我正在尝试与 google gmail 联系人集成我遵循此示例 Google Contacts API version 3.0 我收到此错误请求执行失败:https://www.google.com/m8/feeds/contacts/default/full

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

内心期望:

{"远程服务器返回错误:(400) Bad Request."}

[第 12 行,第 127 列,元素 gd:im] 缺少属性:'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

【问题讨论】:

    标签: c#


    【解决方案1】:

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

    @地址

    @标签?

    @rel?

    @协议?

    @primary?

    约定:

    elementName 必需元素

    elementName ? 可选元素

    elementName ***** 可选元素,允许多个实例

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

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

    【讨论】:

      【解决方案2】:

      问题是在按照上面 Erik 的建议将 IM 添加到联系人条目时... 在 google api 示例中,他们错过了提及 IM 地址

      只需添加 Address = "liz@gmail.com", 到以下

          // Set the contact's IM information.
          newEntry.IMs.Add(new IMAddress()
              {
                  Primary = true,
                  Rel = ContactsRelationships.IsHome,
                  Protocol = ContactsProtocols.IsGoogleTalk,
                  **Address = "liz@gmail.com",**
              });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-03-26
        • 1970-01-01
        • 2021-03-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-11
        相关资源
        最近更新 更多