I am currently using the Facebook and C # APIs.
What I'm trying to do is upload an image to an event.
I tried two methods, but none of them work. Can someone please take a look.
Method 1
Dictionary<string, string> args = new Dictionary<string, string>(); string source = "@test.jpg"; string relpath = "/1234456789/photos"; args.Add("message", "sssssss"); args.Add("access_token", api.AccessToken); args.Add("source", source); api.Post(relpath, args);
Method 2
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Format("http://graph.facebook.com/1234456789/photos")); request.ContentType = "multipart/form-data"; request.Method = "POST"; string path = HttpUtility.UrlEncode("test.jpg"); request.BeginGetRequestStream(ar => { using (StreamWriter writer = new StreamWriter((ar.AsyncState as HttpWebRequest).EndGetRequestStream(ar))) { writer.Write("{0}={1}&", "message", HttpUtility.UrlEncode("Test")); writer.Write("{0} =@ {1}&", "source", path); writer.Write("{0}={1}", "access_token", api.AccessToken); } }, request);
Method 3
WebClient client = new WebClient(); byte[] responseBinary = client.UploadFile("http://localhost:61689/Widgets/test2.aspx", "POST", @"C:\test.jpg"); string response = Encoding.UTF8.GetString(responseBinary); Dictionary<string, string> args = new Dictionary<string, string>(); string relpath = "https://graph.facebook.com/me/picture"; args.Add("message", "sssssss"); args.Add("access_token", GetAccessToken(code)); args.Add("source", response); api.Post(relpath, args);
In method 3, I try to create an answer and write this. I get 400 bad requests.
The image 'test.jpg' is currently located in my website root directory, as well as on its page.
c # facebook
Robert
source share