简体   繁体   中英

post photo to facebook using windows phone app

I am trying to post a photo to facebook wall, for which I am using Facebook c# sdk. I have used the following code :

    var fb = new FacebookClient(App.AccessToken);
            var parameters = new Dictionary<string, object>
   {
        { "message", "Olav is testing Facebook C# SDK" },
        { "picture", "http://download.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=facebooksdk&DownloadId=170794&Build=17672" },
        { "name", "Facebook C# SDK" },
        { "caption", "http://facebooksdk.codeplex.com/" },
        { "description", "The Facebook C# SDK helps .Net developers build web, desktop, Silverlight, and Windows Phone 7 applications that integrate with Facebook." },
        { "privacy", new Dictionary<string, object>
            {
                { "value",  "SELF" }
            }
        }
    };

            fb.PostAsync("me/feed", parameters);

It is working fine for the given picture url. But what if i want the picture to be the one created by the user using the phone app. If I give any value to picture field other than a url, then it gives an error. Can someone please tell how to do this, or is there any other method to post an image from app to facebook wall?

That's not how you share a local photo. What you're doing currently is sharing a link with custom picture,caption,description etc.

To share a photo with c# sdk try this:

    var fb = new FacebookClient(App.AccessToken);       

    var parameters = new Dictionary<string, object>();
    parameters["name"] = "Description for the pic";
    parameters["TestPic"] = new FacebookMediaObject
    {
        ContentType = "image/jpeg",
        FileName = "photo_name.jpg"

    }.SetValue(File.ReadAllBytes(Server.MapPath("~\\Images\\photo_name.jpg")));

    dynamic res = fb.Post("me/Photos", parameters);

    // res.id contains the returned photo id

Replace the Server.MapPath with your photo URI.
Parameter TestPic could be anything you like. It is used as the name in the multipart/form-data when you upload the file.

You can follow this detailed tutorial , if still any problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM