【发布时间】:2011-04-15 14:12:26
【问题描述】:
有没有人有一个在 c# 中通过 AuthSub 获取 google 联系人的工作示例
我已经尝试过这个url,但我无法完成它。
【问题讨论】:
标签: c# google-contacts-api authsub
有没有人有一个在 c# 中通过 AuthSub 获取 google 联系人的工作示例
我已经尝试过这个url,但我无法完成它。
【问题讨论】:
标签: c# google-contacts-api authsub
这是我的一个项目中的一段代码:
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 是一个简单列表的包装器,而 GoogleContactItem 是一个检索信息的包装器。
【讨论】:
我发现这个例子很简单。 link 而且效果很好。
【讨论】: