How to post a photo on the wall?

Does anyone successfully send an image to the current wall of the user? This does not work if there is a picture argument, the url post picture is not displayed! I am using the latest version of the 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); 
+4
source share
3 answers

Here's how I handled posting a photo on a Facebook user’s wall. ImagePath and ImageName were string parameters that I passed to a function containing this code.

  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; } } } 
+7
source

This is a known bug in version 5.0.8. It has been fixed in the current source and will be in the next release.

+1
source

You can use the message in the user’s wall ( "me / photos" )

  [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); } 
+1
source

Source: https://habr.com/ru/post/1346045/


All Articles