POSTリクエストでImageをGraph APIに渡す必要があります(publish_stream権限が必要です)。 Facebookのドキュメントに記載されている内容は正しいです。次に、作業を行う可能性のあるコードの例を示します。メソッド内で使用してください。 (コードはC#です)
凡例 <content>
:情報を入力する必要があります。
更新 コードを改善するコメントを投稿してください。
string ImageData;
string queryString = string.Concat("access_token=", /*<Place your access token here>*/);
string boundary = DateTime.Now.Ticks.ToString("x", CultureInfo.InvariantCulture);
StringBuilder sb = String.Empty;
sb.Append("----------").Append(boundary).Append("\r\n");
sb.Append("Content-Disposition: form-data; filename=\"").Append(/*<Enter you image's flename>*/).Append("\"").Append("\r\n");
sb.Append("Content-Type: ").Append(String.Format("Image/{0}"/*<Enter your file type like jpg, bmp, gif, etc>*/)).Append("\r\n").Append("\r\n");
using (FileInfo file = new FileInfo("/*<Enter the full physical path of the Image file>*/"))
{
ImageData = file.OpenText().ReadToEnd();
}
byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sb.ToString());
byte[] fileData = Encoding.UTF8.GetBytes(ImageData);
byte[] boundaryBytes = Encoding.UTF8.GetBytes(String.Concat("\r\n", "----------", boundary, "----------", "\r\n"));
var postdata = new byte[postHeaderBytes.Length + fileData.Length + boundaryBytes.Length];
Buffer.BlockCopy(postHeaderBytes, 0, postData, 0, postHeaderBytes.Length);
Buffer.BlockCopy(fileData, 0, postData, postHeaderBytes.Length, fileData.Length);
Buffer.BlockCopy(boundaryBytes, 0, postData, postHeaderBytes.Length + fileData.Length, boundaryBytes.Length);
var requestUri = new UriBuilder("https://graph.facebook.com/me/photos");
requestUri.Query = queryString;
var request = (HttpWebRequest)HttpWebRequest.Create(requestUri.Uri);
request.Method = "POST";
request.ContentType = String.Concat("multipart/form-data; boundary=", boundary);
request.ContentLength = postData.Length;
using (var dataStream = request.GetRequestStream())
{
dataStream.Write(postData, 0, postData.Length);
}
request.GetResponse();
私は最終的にこれを試してみましたが、「リモートサーバーからエラー:(400)Bad Request」というメッセージが返されました。私は他の方法を手に入れました。私はあなたが要求変数を2回宣言したことに気付きました.vb.netはそれを好まなかったのです。 – user548084
オハイオ州オハイオ州オハイオ州オハイオ州申し訳ありません私はちょうどそれを編集し、あなたの問題のため...有効なアクセストークンを持っていないときに、通常は返されたエラーは、ブラウザ(GET)リクエストでアクセストークンを使用してそのURIを使用してみても、まだエラーが発生します... –