Hi, 

The full code I am trying to get to work but just fails with a {"The remote 
server returned an error: (404) Not Found."} which isn't very helpful.  If 
I substitute the access token collected by using the p12.key with the one 
from the playground, it works!  Can you see what I am doing wrong?

My Code:


                const string ServiceAccountEmail = 
"[email protected]";

                var certificate = new 
X509Certificate2(HttpContext.Current.Server.MapPath("key.p12"), 
"notasecret", X509KeyStorageFlags.Exportable);

                var serviceAccountCredentialInitializer =
                    new 
ServiceAccountCredential.Initializer(ServiceAccountEmail)
                    {
                        Scopes = new[] { 
"http://picasaweb.google.com/data/"; }
                    }.FromCertificate(certificate);

                var credential = new 
ServiceAccountCredential(serviceAccountCredentialInitializer);

                if 
(!credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Result)
                    throw new InvalidOperationException("Access token 
request failed.");

                GAuthSubRequestFactory authFactory = new 
GAuthSubRequestFactory("lh2", "xxxx");
                //authFactory.Token = "playground token";   (this works but 
is of course only temp)
                authFactory.Token = credential.Token.AccessToken;

                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();


Thanks

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