我正在尝试从 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);