2011-04-15 69 views

回答

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是圍繞一個簡單的列表的包裝和GoogleContactItem是圍繞檢索到的信息的包裝。

+0

@Perry,我想要一個類似的一個到stackoverflow登錄,我將重定向到Gmail輸入密碼,但在這裏我用來獲取通訊錄。謝謝 – vamsivanka 2011-04-15 14:49:46

+0

嘿,我不確定這是你的答案,還是你試圖做別的事情?你能進一步解釋嗎? – Flawless 2011-04-15 21:37:14

0

我發現這個例子很簡單。 link 而且效果很好。