2011-03-31 151 views
4

任何人都可以將照片發佈到當前用戶的牆上嗎?這是行不通的,如果圖片參數是現有的圖片url帖子不顯示!我正在使用最新的FB C#SDK 5.0.8 Beta ...如何在牆上張貼圖片?

var args = new Dictionary<string, object>(); 
args["name"] = "My App"; 
args["link"] = @"http://apps.facebook.com/test/"; 
args["caption"] = "My Caption"; 
args["description"] = "My Description"; 
args["picture"] = @"http://www.test.com/test.jpeg"; 
args["message"] = "My Message"; 
args["actions"] = ""; 
FbClient.PostAsync(@"/me/feed", args); 

回答

1

這是版本5.0.8中的已知錯誤。它已在當前的源代碼中得到修復,並將在下一個版本中發佈。

7

下面是我如何處理張貼照片到Facebook用戶的牆上。 ImagePath和ImageName是我傳入包含此代碼的函數的字符串參數。

var fbApp = new FacebookApp(); 
    var auth = new CanvasAuthorizer(fbApp); 

    if (auth.IsAuthorized()) 
    { 

     //Create a new dictionary of objects, with string keys 
     Dictionary<string, object> parameters = new Dictionary<string, object>(); 

     string strDescription = txtDescription.Text; 

     //Add elements to the dictionary 
     if (string.IsNullOrEmpty(ImagePath) == false) 
     { 
      //There is an Image to add to the parameters     
      FacebookMediaObject media = new FacebookMediaObject 
      { 
       FileName = ImageName, 
       ContentType = "image/jpeg" 
      }; 

      byte[] img = File.ReadAllBytes(ImagePath); 
      media.SetValue(img); 

      parameters.Add("source", media); 
      parameters.Add("message", strDescription); 

      try 
      { 
       dynamic result = fbApp.Api("/me/photos", parameters, HttpMethod.Post); 

      } 
      catch (Exception ex) 
      { 
       //handle error.... 
       string strErr = ex.Message.ToString(); 
       lblValidationMsg.Text = strErr; 
      } 
     }    

    } 
1

可以在用戶使用牆後(「我/照片」

[TestMethod] 
    [DeploymentItem(@".\resources\velas_navidad.gif", @".\")] 
    public void Post_to_photos() 
    { 
     var ImagePath = "velas_navidad.gif"; 
     Assert.IsTrue(File.Exists(ImagePath)); 

     var client = new FacebookClient(token); 
     dynamic parameters = new ExpandoObject(); 

     parameters.message = "Picture_Caption"; 
     parameters.subject = "test 7979"; 
     parameters.source = new FacebookMediaObject 
     { 
       ContentType = "image/gif", 
       FileName = Path.GetFileName(ImagePath) 
     }.SetValue(File.ReadAllBytes(ImagePath)); 

     dynamic result = client.Post("me/photos", parameters); 

     Thread.Sleep(15000); 
     client.Delete(result.id); 
    } 
+0

需要哪些權利這樣做嗎? – daniel 2015-04-16 09:05:13