我目前正在使用Facebook API和C#.
我要做的是将图像上传到活动.
我尝试了两种方法,但似乎都没有用.有人可以看看.
方法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);
Run Code Online (Sandbox Code Playgroud)
方法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);
Run Code Online (Sandbox Code Playgroud)
方法3
WebClient client = new WebClient();
byte[] responseBinary = client.UploadFile("http://localhost:61689/Widgets/test2.aspx", "POST", @"C:\test.jpg");
string …
Run Code Online (Sandbox Code Playgroud)