类似于Simple example to upload photos into google picasa,这是关于python的;这个是关于.NET的。
如何use the ClientLogin protocol,以及如何do the multipart/related form POST,根据Google的要求?
答案 0 :(得分:0)
显然有一个打包的类库可以执行此操作。我真正想要的是执行它所需的HTTP协议。使用Google API documentation for Picasa,这就是我想到的。
请求如下所示:
POST https://picasaweb.google.com/data/feed/api/user/default/albumid/default HTTP/1.1
GData-Version: 2.0
Authorization: GoogleLogin auth=DQAAAJgAAAD_....-tTM2ZliWDzXLA
Content-Type: multipart/related; boundary="1292107594356"
Host: picasaweb.google.com
Content-Length: 5415
Expect: 100-continue
Media multipart posting
--1292107594356
Content-Type: application/atom+xml
<entry xmlns='http://www.w3.org/2005/Atom'>
<title>DesiredFileNameOnGoogle.jpg</title>
<summary>uploaded from PicasaUpload</summary>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/photos/2007#photo'/>
</entry>
--1292107594356
Content-Type: image/jpeg
(binary content here)
--1292107594356--
回复如下:
HTTP/1.1 201 Created
Expires: Sat, 11 Dec 2010 22:46:26 GMT
Date: Sat, 11 Dec 2010 22:46:26 GMT
Cache-Control: private, max-age=0, must-revalidate, no-transform
Set-Cookie: _rtok=y6u5yQV84QUO; Path=/; Secure; HttpOnly
Set-Cookie: S=photos_html=lIi6RQVuq7F1iAQHMpMkUA; Domain=.google.com; Path=/; Secure; HttpOnly
Content-Type: application/atom+xml; charset=UTF-8; type=entry
Vary: Accept, X-GData-Authorization, GData-Version
GData-Version: 2.0
ETag: "YD0qeyI."
Location: https://picasaweb.google.com/data/entry/api/user/1018683/albumid/55399652081/photoid/5549567010?authkey=Gv1sRgCJrQ5qeYxISo5gE
Content-Location: https://picasaweb.google.com/data/entry/api/user/1018683/albumid/55399652081/photoid/5549567010?authkey=Gv1sRgCJrQ5qeYxISo5gE
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Transfer-Encoding: chunked
然后响应中的Atom有效负载如下:
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:exif='http://schemas.google.com/photos/exif/2007' xmlns:app='http://www.w3.org/2007/app' xmlns:gphoto='http://schemas.google.com/photos/2007' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='"YD0qeyI."'>
<id>https://picasaweb.google.com/data/entry/user/1018683/albumid/5549217276399652081/photoid/5549498718938958882</id>
<published>2010-12-11T18:49:18.000Z</published>
<updated>2010-12-11T18:49:18.319Z</updated>
<app:edited>2010-12-11T18:49:18.319Z</app:edited>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#photo'/>
<title>CropperCapture[30].jpg</title>
<summary>woof!</summary>
<content type='image/jpeg' src='https://lh5.googleusercontent.com/_-Mw_MhEEB_U/TQPHrq_XjCI/AAAAAAAAABQ/wu5AI7QfmWQ/CropperCapture%5B30%5D.jpg'/>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://picasaweb.google.com/data/feed/api/user/1018683/albumid/5549217276399652081/photoid/5549498718938958882?authkey=Gv1sRgCJrQ5qeYxISo5gE'/>
<link rel='alternate' type='text/html' href='http://picasaweb.google.com/1018683/DropBox?authkey=Gv1sRgCJrQ5qeYxISo5gE#5549498718938958882'/>
<link rel='http://schemas.google.com/photos/2007#canonical' type='text/html' href='http://picasaweb.google.com/lh/photo/lzJ9Ya6NeZM8sPeVfFcn98QJQ0GDj3dCNP33YlpCH6E'/>
<link rel='self' type='application/atom+xml' href='https://picasaweb.google.com/data/entry/api/user/1018683/albumid/5549217276399652081/photoid/5549498718938958882?authkey=Gv1sRgCJrQ5qeYxISo5gE'/>
<link rel='edit' type='application/atom+xml' href='https://picasaweb.google.com/data/entry/api/user/1018683/albumid/5549217276399652081/photoid/5549498718938958882?authkey=Gv1sRgCJrQ5qeYxISo5gE'/>
<link rel='edit-media' type='image/jpeg' href='https://picasaweb.google.com/data/media/api/user/1018683/albumid/5549217276399652081/photoid/5549498718938958882?authkey=Gv1sRgCJrQ5qeYxISo5gE'/>
<link rel='http://schemas.google.com/photos/2007#report' type='text/html' href='http://picasaweb.google.com/lh/reportAbuse?uname=1018683&aid=5549217276399652081&iid=5549498718938958882'/>
<gphoto:id>5549498718938958882</gphoto:id>
<gphoto:albumid>5549217276399652081</gphoto:albumid>
<gphoto:access>private</gphoto:access>
<gphoto:width>441</gphoto:width>
<gphoto:height>287</gphoto:height>
<gphoto:size>26876</gphoto:size>
<gphoto:checksum/>
<gphoto:timestamp>1292093358000</gphoto:timestamp>
<gphoto:imageVersion>20</gphoto:imageVersion>
<gphoto:commentingEnabled>true</gphoto:commentingEnabled>
<gphoto:commentCount>0</gphoto:commentCount>
<gphoto:license id='0' name='All Rights Reserved' url=''>ALL_RIGHTS_RESERVED</gphoto:license>
<exif:tags>
<exif:imageUniqueID>abfde2a4ab9f9e177865ba4fd50e7edb</exif:imageUniqueID>
</exif:tags>
<media:group>
<media:content url='https://lh5.googleusercontent.com/_-Mw_MhEEB_U/TQPHrq_XjCI/AAAAAAAAABQ/wu5AI7QfmWQ/CropperCapture%5B30%5D.jpg' height='287' width='441' type='image/jpeg' medium='image'/>
<media:credit>User Name</media:credit>
<media:description type='plain'>woof!</media:description>
<media:keywords/>
<media:thumbnail url='https://lh5.googleusercontent.com/_-Mw_MhEEB_U/TQPHrq_XjCI/AAAAAAAAABQ/wu5AI7QfmWQ/s72/CropperCapture%5B30%5D.jpg' height='47' width='72'/>
<media:thumbnail url='https://lh5.googleusercontent.com/_-Mw_MhEEB_U/TQPHrq_XjCI/AAAAAAAAABQ/wu5AI7QfmWQ/s144/CropperCapture%5B30%5D.jpg' height='94' width='144'/>
<media:thumbnail url='https://lh5.googleusercontent.com/_-Mw_MhEEB_U/TQPHrq_XjCI/AAAAAAAAABQ/wu5AI7QfmWQ/s288/CropperCapture%5B30%5D.jpg' height='188' width='288'/>
<media:title type='plain'>CropperCapture[30].jpg</media:title>
</media:group>
</entry>
答案 1 :(得分:0)
尝试一下对我有用的代码示例,希望能与您合作
GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory("lh2", "Your application name");
authFactory.Token = (string)HttpContext.Current.Session["token"];
PicasaService picasaService= new PicasaService(authFactory.ApplicationName);
service.RequestFactory = authFactory;
Uri postUri = new Uri(PicasaQuery.CreatePicasaUri(Constants.CurrentUser, albumId));
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
System.IO.FileStream fileStream = fileInfo.OpenRead();
PicasaEntry entry = (PicasaEntry)picasaService.Insert(postUri, fileStream, "image/jpeg", filePath);
fileStream.Close();