【问题标题】:Not able to retrieve the gmail contact photo无法检索 gmail 联系人照片
【发布时间】:2012-12-17 05:42:40
【问题描述】:

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

在 gmail 中登录用户的朋友。我得到了gridview中的联系人列表。但我是

无法获取任何联系人的个人资料照片。我在

中动态添加数据列

网格视图。

这是我检索照片的代码:

 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

无论如何我都无法获取联系人照片。

感谢任何帮助。

谢谢

【问题讨论】:

  • 我仍然无法获取图像。谁能提供一些代码。我迫切需要它

标签: c# asp.net google-api


【解决方案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;
}

【讨论】:

    【解决方案2】:

    我已成功使用 GData Library 检索照片。照片作为流返回。

    以下代码检索流

                    requestFactory = new GOAuthRequestFactory("c1", ApplicationName, parameters);
                service = new ContactsService(ApplicationName);
                service.RequestFactory = requestFactory;
    
                resultsStream = service.Query(new Uri(Uri));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多