Note that there are some explanatory texts on larger screens.

plurals
  1. POC# & Facebook API
    text
    copied!<p>I'm currently using the Facebook API and C#.</p> <p>What i'm trying to do is upload an image to an event. </p> <p>I've tried two methods, but neither seem to work. Could someone please take a look. </p> <p><strong>Method 1</strong></p> <pre><code> Dictionary&lt;string, string&gt; args = new Dictionary&lt;string, string&gt;(); 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); </code></pre> <p><strong>Method 2</strong></p> <pre><code> 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 =&gt; { using (StreamWriter writer = new StreamWriter((ar.AsyncState as HttpWebRequest).EndGetRequestStream(ar))) { writer.Write("{0}={1}&amp;", "message", HttpUtility.UrlEncode("Test")); writer.Write("{0}=@{1}&amp;", "source", path); writer.Write("{0}={1}", "access_token", api.AccessToken); } }, request); </code></pre> <p><strong>Method 3</strong></p> <pre><code> 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&lt;string, string&gt; args = new Dictionary&lt;string, string&gt;(); 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); </code></pre> <p>In method 3 i'm trying to create the response and write that. I'm getting 400 bad request.</p> <p>The image 'test.jpg' currently sits in my website root, same as the page calling it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload