获取 Gmail 通讯录图片



我正在尝试使用google api 3从gmail获取Google联系人图像。

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

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

而不是

cr.GetPhoto(entry)

cr.Service.Query(entry.PhotoUri);

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

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

相关内容

  • 没有找到相关文章

最新更新