1

I want to upload an image on user profile. I have an image in Bitmap form. I am using this code...

        Bitmap bit = new Bitmap("E:\\abc.jpg");
        MemoryStream ms = new MemoryStream();

        bit.Save(ms, ImageFormat.Jpeg);

        byte[] buffer = ms.ToArray();


        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://graph.facebook.com/me/photos?access_token=" + acc_token);

        req.Method = "POST";
        req.ContentLength = buffer.Length;
        //req.ContentType = "application/x-www-form-urlencoded";
        req.ContentType = "image/jpeg";                       

        Stream rq_strm = req.GetRequestStream();
        rq_strm.Write(buffer, 0, buffer.Length);
        rq_strm.Close();

        HttpWebResponse res = (HttpWebResponse)req.GetResponse();     //got error here
        Response.Write("RESPONSE: " + res.StatusDescription);

I got the error The remote server returned an error: (400) Bad Request. Where am I wrong ?

Sagar
  • 7,115
  • 6
  • 21
  • 35
  • http://stackoverflow.com/questions/4898950/posting-image-from-net-to-facebook-wall-using-the-graph-api – Ibrahim Nov 24 '12 at 19:52

1 Answers1

0

Basically, this means that the server didn't recognize your request. Typically for an API, this means that the API couldn't decipher something, or it was missing an important feature. In this case, it determined that you included no source tag. Typically, this is sent via an HTML form with the <input type='file'> tag. The way to emulate this is rather complex, but this question will point you in the right direction.

Community
  • 1
  • 1
PearsonArtPhoto
  • 38,970
  • 17
  • 111
  • 142