通过AuthSub c#获取Google联系人

时间:2011-04-15 14:12:27

标签: c# google-contacts authsub

是否有人在c#

中通过AuthSub获取谷歌联系方式

我试过这个url,但我无法完成它。

2 个答案:

答案 0 :(得分:0)

以下是我的一个项目中的一段代码:

    public class GoogleContactsProvider : IContactProvider
{
    #region IContactProvider Members

    /// <summary>
    /// Gets the contacts list form the contact provider.
    /// </summary>
    /// <returns></returns>
    public EntityCollection<IContactItem> GetContactsList()
    {
        EntityCollection<IContactItem> collection = new EntityCollection<IContactItem>();

        // Setup the contacts request (autopage true returns all contacts)
        RequestSettings requestSettings = new RequestSettings("AgileMe", UserName, Password);
        requestSettings.AutoPaging = true;
        ContactsRequest contactsRequest = new ContactsRequest(requestSettings);

        // Get the feed
        Feed<Contact> feed = contactsRequest.GetContacts();

        // create our collection by looping through the feed
        foreach (Contact contact in feed.Entries)
        {
            GoogleContactItem newContact = new GoogleContactItem();
            newContact.Name = contact.PrimaryEmail.Address;
            newContact.Summary = contact.Summary;

            collection.Add(newContact);
        }

        return collection;
    }

    /// <summary>
    /// Gets or sets the name of the user for the contact provider.
    /// </summary>
    /// <value>The name of the user.</value>
    public string UserName { get; set; }

    /// <summary>
    /// Gets or sets the password for the contact provider.
    /// </summary>
    /// <value>The password.</value>
    public string Password { get; set; }

    #endregion
}

EntityCollection是一个简单List的包装器,而GoogleContactItem是检索到的信息的包装器。

答案 1 :(得分:0)

我发现这个例子很简单。 link 而且效果很好。