Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post picture on the wall?

Does anybody sucessfuly post picture to current user's wall? This is not working, if picture argument is existing picture url post is not shown! I'm using latest 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);
like image 256
Matjaz Bravc Avatar asked Jan 21 '23 02:01

Matjaz Bravc


1 Answers

Here is how I handled posting a photo to the Facebook User's wall. ImagePath and ImageName were string parameters that I passed into the function that contains 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;
            }
        }            

    }
like image 183
landsteven Avatar answered Apr 21 '23 11:04

landsteven