我正在创建Google集成的asp.net应用程序。我想要检索所有信息
在gmail中登录用户的朋友。我在gridview中获得了联系人列表。但我
无法获取任何联系人的个人资料照片。我在
中动态添加datacolumnsgridview的。
以下是我检索照片的代码:
RequestSettings rs = new RequestSettings(App_Name, Uname, Password_property);
rs.AutoPaging = true;
ContactsRequest cr = new ContactsRequest(rs);
Feed<Contact> f = cr.GetContacts();
foreach (Contact t in f.Entries)
{
Stream photo = cr.Service.Query(t.PhotoUri);
if (photo != null)
{
dr1["Profile Pic"] = System.Drawing.Image.FromStream(photo);
}
}
崩溃并说远程服务器返回错误。
然后我尝试了另一个代码:
Stream photo = cr.GetPhoto(t);
if (photo != null)
{
dr1["Profile Pic"] = System.Drawing.Image.FromStream(photo);
}
它也会崩溃并给出错误
Google.GData.Client.GDataNotModifiedException : Content not modified
无论如何我无法收到联系人照片。
感谢任何帮助。
由于
答案 0 :(得分:1)
以下代码适用于我:
public static List<ContactDetail> GetAllContact(string username, string password)
{
List<ContactDetail> contactDetails = new List<ContactDetail>();
ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
RequestSettings rs = new RequestSettings("W7CallerID", username, password);
ContactsRequest cr = new ContactsRequest(rs);
Feed<Contact> feed = cr.GetContacts();
foreach (Contact entry in feed.Entries)
{
ContactDetail contact = new ContactDetail
{
Name = entry.Name.FullName,
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 : "",
Details = entry.Content,
Pic = System.Drawing.Image.FromStream(cr.Service.Query(entry.PhotoUri))
};
contactDetails.Add(contact);
}
return contactDetails;
}
答案 1 :(得分:0)
我设法使用GData Library成功检索照片。照片以流的形式返回。
以下代码检索流
requestFactory = new GOAuthRequestFactory("c1", ApplicationName, parameters);
service = new ContactsService(ApplicationName);
service.RequestFactory = requestFactory;
resultsStream = service.Query(new Uri(Uri));