开发者

How to post photo to album in facebook graph api Asp.NET

i wrote an application for facebook but i couldn't upload image to album that i created, code is in below, thanks for your help.

        Facebook.FacebookAPI api = new Facebook.FacebookAPI(GetAccessToken());
        Dictionary<string, string> album = new Dictionary<string, string>();
        album.Add("name", "Test Album");
        album.Add("message", "Message here!");
        JSONObject result = api.Post("me/albums", album);
        string AlbumId = result.Dictionary["id"].String;

        Dictionary开发者_JAVA技巧<string, string> photo = new Dictionary<string, string>();
        photo.Add("message", "test Message");
        photo.Add("source", "tgw.jpg");
        JSONObject photoResult = api.Post("/" + AlbumId + "/photos", photo);


Does this works for you?

string photoPath = @"..\..\..\Facebook.Tests\bin\Release\monkey.jpg";
            string albumId = ConfigurationManager.AppSettings["AlbumId"];
            byte[] photo = File.ReadAllBytes(photoPath);

            FacebookApp app = new FacebookApp();
            dynamic parameters = new ExpandoObject();
            parameters.access_token = ConfigurationManager.AppSettings["AccessToken"];
            parameters.message = "This is a test photo of a monkey that has been uploaded " +
                                 "by the Facebook C# SDK (http://facebooksdk.codeplex.com)" +
                                 "using the Graph API";
            var mediaObject = new FacebookMediaObject
            {
                FileName = "monkey.jpg",
                ContentType = "image/jpeg",
            };
            mediaObject.SetValue(photo);
            parameters.source = mediaObject;

            dynamic result = app.Api(String.Format("/{0}/photos", albumId), parameters, HttpMethod.Post);

Taken from here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜