0

MVC3 C# を使用して Facebook に写真をアップロードしようとしています。コードは正常に実行されていますが、写真が Facebook にアップロードされていません。ID と App Secret を追加しています。いろいろ試して何日も頑張ったけど結果ゼロ。これが私のコントローラーのコードです

[HttpPost][HttpGet]

public ActionResult Profile(HttpPostedFileBase file, FacebookOAuthResult facebookOAuthResult) {
  dynamic args = new ExpandoObject();
  args = new Dictionary<string, object>();
  args["message"] = "hi";
  args["picture"] = "http://apps.facebook.com/Uploads/photos";
  string accesstoken=FacebookWebContext.Current.AccessToken;
  FacebookClient fbApp = new FacebookClient(accesstoken);
  try {
    fbApp.Post("MYAPPID" + "/Photos", args);
  } catch (FacebookOAuthException ex) {
            //
  }
  // Verify that the user selected a file
  if (file != null && file.ContentLength > 0) {
    var path1 = Path.Combine(Server.MapPath("~/Content/uppoads"), file.FileName);
    //file.SaveAs(path1);
    fbApp.Post("MYAPPID" + "/photos", path1);
  }
  // redirect back to the index action to show the form once again
  return RedirectToAction("Profile");
}

誰かが解決策を見つけるのを手伝ってくれますか? 前もって感謝します。

4

1 に答える 1

0

写真のローカル パスを Facebook に投稿します。FB はそれが何であるかを知りません。
投稿本文に写真をバイナリとして投稿する必要があります。

var media = new Facebook.FacebookMediaObject();
var filebytes  = System.IO.File.ReadAllBytes(path1);
media.SetValue(filebytes);
fbApp.Post("248050331932489" + "/photos", media);
于 2012-07-10T05:57:40.703 に答える