获取gmail联系人图片

时间:2013-11-05 08:33:04

标签: c# google-api

我正在尝试使用google api 3从gmail获取谷歌联系人图片。

我使用下面的代码来阅读流来获取照片:

public static void DownloadPhoto(ContactsRequest cr, Contact entry)
    {
        string filename = "c:\\gcontacts\\" + entry.GetHashCode() + ".jpg";

        Stream photoStream = cr.GetPhoto(entry);
        FileStream outStream = File.OpenWrite(filename);

        try
        {                
            byte[] buffer = new byte[photoStream.Length];

            photoStream.Read(buffer, 0, (int)photoStream.Length);
            outStream.Write(buffer, 0, (int)photoStream.Length);

            photoStream.Close();
            outStream.Close();
        }
        catch (Exception ex)
        {

        }
    }

我收到以下错误:

Content not modified

https://www.google.com/m8/feeds/photos/media/myemail/610f985888b0911

我使用此功能来调用服务

public static void PrintAllContacts(ContactsRequest cr)
    {
        Feed<Contact> f = cr.GetContacts();
        foreach (Contact entry in f.Entries)
        {
            if (entry.Name.FullName != null)
            {
                Console.WriteLine(entry.Name.FullName);
                Console.WriteLine(entry.PhotoUri.AbsoluteUri);

                DownloadPhoto(cr, entry);
            }
        }
    }

这是请求

RequestSettings rsLoginInfo = new RequestSettings("appname", "@gmail.com", "pass");
        rsLoginInfo.AutoPaging = true;
        ContactsRequest cRequest = new ContactsRequest(rsLoginInfo);

2 个答案:

答案 0 :(得分:1)

而不是

cr.GetPhoto(entry)

使用

cr.Service.Query(entry.PhotoUri);

答案 1 :(得分:0)

它说请求中存在问题。您应该检查您提出请求的位置并与我们分享,您没有在问题中发布该部分。

您可以在此处找到文档:https://developers.google.com/google-apps/contacts/v3/#retrieving_a_contacts_photo