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