检索gmail联系信息时出现对象引用错误

时间:2011-12-19 11:21:14

标签: c# asp.net google-api

我正在创建Google集成的asp.net应用程序。我想要检索所有信息

在gmail中登录用户的朋友。我在列表框中找到了联系人列表。现在我想要那个

当我点击列表框中的任何联系人时,它应显示所有信息

关于该联系人。

以下是代码:

List<ContactDetail> contactDetails = new List<ContactDetail>();
ContactsQuery query = new     
ContactsQuery(ContactsQuery.CreateContactsUri(txtEmail.Text));

ContactsFeed feed = GContactService.Query(query);
foreach (ContactEntry entry in feed.Entries)
   {
       ContactDetail contact = new
       ContactDetail
       {
           Name = entry.Title.Text,
           EmailAddress1 = entry.Emails.Count >= 1 ? entry.Emails[0].Address : "",
           EmailAddress2 = entry.Emails.Count >= 2 ? entry.Emails[1].Address : "",
           Phone = entry.Phonenumbers.Count >= 1 ? entry.Phonenumbers[0].Value : "",
           Address = entry.PostalAddresses.Count >= 1 ? 
           entry.PostalAddresses[0].Value : "",
           Details = entry.Content.Content

       };

      contactDetails.Add(contact);
  }

但我在

上收到以下错误
ContactsQuery(ContactsQuery.CreateContactsUri(txtEmail.Text));

错误:

Object reference not set to an instance of an object.

Stack Trace:

 [NullReferenceException: Object reference not set to an instance of an object.]
 Friends.GmailFriends.GetAllContact() in C:\Documents and Settings\Isha.Jain.QUAYMOHALI
 \Desktop\Friends\Friends\GmailFriends.aspx.cs:36
 Friends.GmailFriends.lstContacts_SelectedIndexChanged(Object sender, EventArgs e) in 
 C:\Documents and Settings\Isha.Jain.QUAYMOHALI\Desktop\Friends\Friends
 \GmailFriends.aspx.cs:95
 System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e) +118
 System.Web.UI.WebControls.ListBox.RaisePostDataChangedEvent() +143

我无法理解为什么会收到此错误。

感谢任何帮助

感谢。

0 个答案:

没有答案