2012-10-31 51 views
1

我正在使用Facebook c#SDK在用戶牆上發佈狀態&圖像。使用Facebook發佈後未上傳圖像c#SDK

我能夠發佈狀態,但圖像沒有得到公佈

這裏是我的代碼:

[HttpPost] 
    public ActionResult PostPhotoOnWall(HttpPostedFileBase file) 
    { 
     var client = new FacebookClient(); 

     // Post to user's wall 
     var postparameters = new Dictionary<string, object>(); 

     postparameters["access_token"] = Session["access_token"].ToString(); 
     postparameters["picture"] = "http://localhost:8691/Content/themes/base/images/12WIPJ50240-2V91.jpg"; 

     var result = client.Post("/me/feed", postparameters); 

     return View("PostPhoto"); 
    } 

在用戶牆狀態發佈沒有圖像。

任何人都可以幫助我。

回答

1

我解決它,貝婁是代碼

[HttpPost] 
    public ActionResult PostPhotoOnWall(HttpPostedFileBase file) 
    { 
     var filename = Path.GetFileName(file.FileName); 

     var client = new FacebookClient(); 

     // Post to user's wall 
     var postparameters = new Dictionary<string, object>(); 
     var media = new FacebookMediaObject 
     { 
      FileName = filename, 
      ContentType = "image/jpeg" 
     }; 
     var path = Path.Combine(Server.MapPath("~/Content/themes/base/images"),filename); 
     file.SaveAs(path); 

     byte[] img = System.IO.File.ReadAllBytes(path); 
     media.SetValue(img); 

     postparameters["source"] = media; 
     postparameters["access_token"] = Session["access_token"].ToString(); 
    // postparameters["picture"] = "http://localhost:8691/Content/themes/base/images/12WIPJ50240-2V91.jpg"; 

     var result = client.Post("/me/photos", postparameters); 

     return View("PostPhoto"); 
    } 
相關問題