2012-07-09 59 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) 
    ....