C# Google API Contact.SetPhoto

本文关键字:SetPhoto Contact API Google | 更新日期: 2023-09-27 18:35:11

以下代码在尝试检索联系人时返回错误(403 禁止访问)。

Contact contact = cr.Retrieve<Contact>(contactURI);

我基于Google的配置文件API页面的这段代码。 https://developers.google.com/google-apps/profiles/。 我将不胜感激任何反馈。

RequestSettings settings = new RequestSettings("Add Profile Photo", "consumerKey", "consumerSecret", username, domain);
ContactsRequest cr = new ContactsRequest(settings);
Uri contactURI = new Uri("http://www.google.com/m8/feeds/profiles/domain/" + domain + "/full/" + username);
Contact contact = cr.Retrieve<Contact>(contactURI);
Stream outStream = File.OpenRead("C:''temp''profilePic.jpg");
try
{
    cr.SetPhoto(contact, outStream);
}
catch (GDataVersionConflictException e)
{
    throw new Exception("Exception setting photo: " + e.Message);
}

C# Google API Contact.SetPhoto

您必须将

RequestSettings 构造函数中的 "consumerKey" 和 "consumerSecret" 替换为应用程序的 OAuth Consumer Key 和 Secret。

文档列表 API 的文档包含许多有关身份验证的详细信息(和 C# 代码),改用联系人 API 应该很容易适应。

此外,如果要使用 OAuth 2.0(推荐),请检查库中包含的完整示例:http://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/oauth2_sample/oauth2demo.cs