[英]How to upload image on facebook using graph api?
我想在用戶個人資料上上傳圖片。 我有Bitmap
形式的圖像。 我正在使用此代碼...
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);
我收到錯誤The remote server returned an error: (400) Bad Request.
我哪里錯了?
基本上,這意味着服務器無法識別您的請求。 通常,對於API而言,這意味着API無法解密某些內容,或者缺少重要功能。 在這種情況下,它確定您不包含source
標簽。 通常,這是通過帶有<input type='file'>
標記的HTML表單發送的。 模擬此方法的方法相當復雜,但是此問題將為您指明正確的方向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.