【问题标题】:How to add my local contact to gmail account?如何将我的本地联系人添加到 gmail 帐户?
【发布时间】:2016-01-15 22:49:17
【问题描述】:

我有与 gmail 帐户相关的应用程序。我想将我的本地数据库联系人添加到 gmail 帐户。我已经提到了这个链接:how to create google contact? 这可能吗?请建议我实现这一目标的方法。

【问题讨论】:

    标签: c# gdata gmail-api google-contacts-api


    【解决方案1】:

    您无法使用gmail-api 创建联系人,但Contacts API: Creating Contacts 会满足您的需求:

    public static Contact CreateContact(ContactsRequest cr)
    {
      Contact newEntry = new 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@gmail.com"
          });
      newEntry.Emails.Add(new EMail()
          {
            Rel = ContactsRelationships.IsWork,
            Address = "liz@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"));
      Contact createdEntry = cr.Insert(feedUri, newEntry);
      Console.WriteLine("Contact's ID: " + createdEntry.Id)
      return createdEntry;
    }
    

    【讨论】:

    • @Tholle 谢谢。这会在 gmail 帐户中创建新联系人,但不会显示在联系人列表中。我必须从搜索中打开“Elizabeth Bennet”,然后我必须编辑并保存联系人才能将其添加到联系人列表中。
    猜你喜欢
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    相关资源
    最近更新 更多