1

我正在尝试从 gmail 获取 google 联系人图片,使用google api 3.

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

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);
4

2 回答 2

1

代替

cr.GetPhoto(entry)

利用

cr.Service.Query(entry.PhotoUri);
于 2014-12-10T13:58:40.350 回答
0

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

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

于 2013-11-05T08:45:46.507 回答