2012-07-09 38 views
0

我想通過我的C#應用​​程序中的Google Contacts API獲取聯繫人列表。如何解析C#中Google Contacts API的xml響應

以下是我使用拉谷歌通訊錄中的代碼,但不知道在解析響應:

 OAuthGContacts _google = new OAuthGContacts(); 
     if (Request["code"] == null) 
     { 
      Response.Redirect(_google.AuthorizationLinkGet()); 

     } 
     else 
     { 
       //Get the access token and secret. 
      _google.AccessTokenGet(Request["code"]); 

      if (_google.Token.Length > 0) 
      { 
      string _contactResponse = _google.WebRequest(OAuthGContacts.Method.GET, "https://www.google.com/m8/feeds/contacts/default/full?access_token=" + _google.Token, string.Empty); 
      XmlReader reader = XmlReader.Create(new StringReader(_contactResponse)); 
      SyndicationFeed feed = SyndicationFeed.Load(reader); 
      reader.Close(); 
      } 
     } 

如何解析拉谷歌通訊錄中的響應,請建議。

回答

1

您不需要解析任何XML響應以在C#應用程序中獲取聯繫人列表。 Google的Data API提供了這樣做的功能。 Here是一個.NET示例。如果您看到該協議,那麼只需單擊.NET標籤,即可看到以下代碼

public static void PrintAllContacts(ContactsRequest cr) 
{ 
    Feed<Contact> f = cr.GetContacts(); 
    foreach (Contact entry in f.Entries) 
    ....