I want to upload photos from my WP7 application to picasa web. when I
m trying to upload I m getting unauthorised access exception. Here is
my code can any one throw some light on this why I m getting this
error .

        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        public delegate void UploadPhotoCallback(bool success, string
message);

        public static void UploadPhoto(string albumId, string
originalFileName, byte[] photo, UploadPhotoCallback callback)
        {
            string Username = "mailmugu";
            string AuthToken = "R3wxDZxHfixvDaQzkpAJXICY";

            try
            {
                var url = string.Format("http://picasaweb.google.com/
data/feed/api/user/{0}/albumid/{1}", Username, albumId);
                var request = WebRequest.Create(new Uri(url)) as
HttpWebRequest;
                //request.ContentType = HttpFormPost.ImageJpeg;
                //request.Method = HttpMethods.Post;

                request.ContentType = "image/jpeg";
                request.Method = "POST";
                request.Headers[HttpRequestHeader.Authorization] =
"GoogleLogin auth=" + AuthToken;

                request.BeginGetRequestStream(new
AsyncCallback(UploadGetRequestCallback),
                                              new UploadRequestState
                                                  {
                                                      Request =
request,
                                                      Callback =
callback,
                                                      Photo = photo,
                                                      FileName =
originalFileName
                                                  });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                //throw new
MyException(MyResources.ErrorUploadingPhotoMessage, e);
            }
        }

                 private static void UploadGetRequestCallback(IAsyncResult ar)
        {
            try
            {
                var state = (UploadRequestState)ar.AsyncState;
                HttpWebRequest request = state.Request;

                // End the operation
                var stream = request.EndGetRequestStream(ar);

                stream.Write(state.Photo, 0, state.Photo.Length);
                stream.Close();

                request.BeginGetResponse(UploadGetResponseCallback,
state);
            }
            catch (Exception e)
            {
                //throw new
MyException(MyResources.ErrorUploadingPhotoMessage, e);
            }
        }

                private static void UploadGetResponseCallback(IAsyncResult ar)
        {
            UploadRequestState state = null;
            try
            {
                state = (UploadRequestState)ar.AsyncState;
                HttpWebRequest request = state.Request;

                // End the operation
                HttpWebResponse response =
(HttpWebResponse)request.EndGetResponse(ar);

                if (response != null)
                {
                    response.Close();
                }

                if (state.Callback != null)
                {
                    MessageBox.Show("Uploaded Sucessfully");
                    //state.Callback(true,
MyResources.PhotosUploadedMessage);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error" + e.Message);
                Console.Write(e);
                //if (state != null && state.Callback != null)
                //state.Callback(false,
MyResources.ErrorSavingImageMessage);
            }


        }

        public class UploadRequestState
        {
            public HttpWebRequest Request { get; set; }

            public UploadPhotoCallback Callback { get; set; }

            public byte[] Photo { get; set; }

            public string FileName { get; set; }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string albumId = "Picasa";
            string Filename = "Test";
            UploadRequestState _uploadReq = new UploadRequestState();
            Uri myuri = new Uri("/Images/Test.jpg",
UriKind.RelativeOrAbsolute);
            BitmapImage btmMap = new BitmapImage(myuri);
            image1.Source=btmMap;
            WriteableBitmap bmp = new
WriteableBitmap(btmMap.PixelWidth,btmMap.PixelHeight);
            MemoryStream ms = new MemoryStream();
            // write an image into the stream
            Extensions.SaveJpeg(bmp, ms,
                btmMap.PixelWidth, btmMap.PixelHeight, 0, 100);
            byte[] Photo = ms.ToArray();
            UploadPhoto(albumId,Filename,Photo,_uploadReq.Callback);
        }
    }

-- 
You received this message because you are subscribed to the Google Groups 
"Google Picasa Web Albums API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-picasa-data-api?hl=en.

Reply via email to