gpt4 book ai didi

c# - 在 .NET 中的 Picasa 中创建新相册

转载 作者:行者123 更新时间:2023-11-30 15:06:44 25 4
gpt4 key购买 nike

我正在尝试将相册发布到 picasa,但总是收到“错误请求”响应。我应该改用 HttpRequest 类吗?

System.Net.WebClient wc = new System.Net.WebClient();
wc.Headers.Add("Authorization", "AuthSub token=\"" + token + "\"");
wc.Headers.Add("GData-Version", "2");

string data = "<entry xmlns='http://www.w3.org/2005/Atom' " +
"xmlns:media='http://search.yahoo.com/mrss/' " +
"xmlns:gphoto='http://schemas.google.com/photos/2007'>" +
"<title type='text'>" + name + "</title>" +
"<summary type='text'>" + descr + "</summary>" +
"<gphoto:location>asd</gphoto:location>" +
"<gphoto:access>" + access + "</gphoto:access>" +
"<gphoto:timestamp>1152255600000</gphoto:timestamp>" +
"<media:group>" +
"<media:keywords>adds</media:keywords>" +
"</media:group>" +
"<category scheme='http://schemas.google.com/g/2005#kind' " +
"term='http://schemas.google.com/photos/2007#album'></category>" +
"</entry>";


try
{
string response = wc.UploadString("https://picasaweb.google.com/data/feed/api/user/default", "post", data);
return response;
}

catch (Exception e)
{
return e.ToString();
}

最佳答案

Google 为 picasa [.net] 集成提供了一个方便的 API:

http://code.google.com/apis/picasaweb/docs/1.0/developers_guide_dotnet.html

手写所有代码毫无意义!

这是一些代码(vb.net,但很简单):

Public Shared Function CreateAlbum(ByVal albumTitle As String) As AlbumAccessor

Dim newAlbum As New AlbumEntry()
newAlbum.Title.Text = albumTitle

Dim ac As New AlbumAccessor(newAlbum)
ac.Access = "public"

Dim feedUri As New Uri(PicasaQuery.CreatePicasaUri(ConfigurationManager.AppSettings("GData_Email")))
Dim albumEntry As PicasaEntry = CreateAuthenticatedRequest().Insert(feedUri, newAlbum)

Return New AlbumAccessor(albumEntry)

End Function

Public Shared Function CreateAuthenticatedRequest() As PicasaService
Dim service As New PicasaService(ConfigurationManager.AppSettings("GData_AppName"))
service.setUserCredentials(ConfigurationManager.AppSettings("GData_Email"), ConfigurationManager.AppSettings("GData_Password"))
Return service
End Function

关于c# - 在 .NET 中的 Picasa 中创建新相册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7341829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com