Hi Prerana,

I am using a different method as follows.  I haven't added any Meta Data to 
the photos (as that isn't important to my use case) but I guess there 
should be a way to add it.  It will be worth you taking a look.  My code is 
below.  I have a question for you as I am also at my wits end!  The code 
below uses an Access Token that I get from OAuth 2.0 Playground.  This 
works but I need to set up a refresh token in my own app so that I can get 
a new access token when the current one expires.  I have tried this for a 
few hours and as Picasa hasn't been updated like the other APIs I can't get 
it to work!  Would you mind posting your code to help me please.  Are you 
using a service account or a web application account to get the access 
token?  Your help is appreciated and I hope the code below helps you.

using Google.GData.Photos;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Extensions.Location;

                GAuthSubRequestFactory authFactory = new 
GAuthSubRequestFactory("lh2", "my-app");
                authFactory.Token = "Token taken from Playground";

                PicasaService service = new 
PicasaService(authFactory.ApplicationName);
                service.RequestFactory = authFactory;
                Uri postUri = new 
Uri(PicasaQuery.CreatePicasaUri("default", AlbumID));

                System.IO.FileInfo fileInfo = new 
System.IO.FileInfo(sFilename);
                System.IO.FileStream fileStream = fileInfo.OpenRead();

                PicasaEntry entry = (PicasaEntry)service.Insert(postUri, 
fileStream, "image/jpeg", sFilename);

                fileStream.Close();

                string rtnURL = entry.Media.Content.Url.ToString();


Thanks in advance!

Ben

On Wednesday, May 20, 2015 at 3:16:53 PM UTC+1, Prerana Polekar wrote:
>
> Hello All,
> I am trying to upload a image with metadata using Picasa Web Album Data 
> API version 2.0 in C#. Its throwing 'Bad Request' error. The error does not 
> indicate which part in request is missing or where I am going wrong. The 
> image upload without metadata works perfectly. Following is the code :
>
>
>      byte[] image = System.IO.File.ReadAllBytes(fullimagepath);
>                 int imglenth= image.Length;
>                string rawImgXml="<entry xmlns=\'http://www.w3.org/2005/
> Atom\'>"+"\n"+
>                     "<title>plz-to-love-realcat.jpg</title>"+"\n"+
>                     "<summary>Real cat wants attention too</summary>"+"\n"
> +
>                     "<category scheme=\"http://schemas.google.com/g/2005#
> kind\""+
>                     "term=\"http://schemas.google.com/photos/2007#photo\"/
> >"+"\n"+
>                     "</entry>";
>
>                 string data = "";
>                  data ="\nMedia multipart posting\n"+
>                           "--P4CpLdIHZpYqNn7\n"+
>                           "Content-Type: application/atom+xml\n\n"+
>                             rawImgXml + "\n"
>                            +"--P4CpLdIHZpYqNn7\n"
>                            +"Content-Type: image/jpeg\n\n"+
>                             "--P4CpLdIHZpYqNn7--";
>
>                 int length=data.Length+imglenth;
>
>                 HttpWebRequest request = (HttpWebRequest)WebRequest.Create
> ("https://picasaweb.google.com/data/feed/api/user/"+tc.userId+"/albumid/"+
> "6150508893827643953"+"?access_token="+tc.auth_Token);
>                 byte[] bytes;
>                 bytes = System.Text.Encoding.ASCII.GetBytes(data);
>                 request.ContentType = "multipart/related; boundary=
> P4CpLdIHZpYqNn7";
>                 request.ContentLength = length;
>                 request.Headers.Add("GData-Version","2");
>                 request.Headers.Add("MIME-Version","1.0");
>                 request.Method = "POST";
>                 Stream requestStream = request.GetRequestStream();
>                 requestStream.Write(image, 0, image.Length);
>                 requestStream.Write(bytes, 0, bytes.Length);
>                 requestStream.Close();
>                 HttpWebResponse response;
>                 response = (HttpWebResponse)request.GetResponse();
>
>                 Stream responseStream = response.GetResponseStream();
>                 string responseStr = new StreamReader(responseStream).
> ReadToEnd();
>
>
> Where am I going wrong? Instead of attaching the image binary data in the 
> string named 'data' I am writing it to the stream, is that the culprit? Any 
> suggestions or directions will be of great help. Thanks a ton in advance!
>
> -Prerana  
>
>
>                   
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Picasa Web Albums API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-picasa-data-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to