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

谁说胖子不能爱 提交于 2019-12-25 03:24:25

问题


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<string, string> photo = new Dictionary<string, string>();
        photo.Add("message", "test Message");
        photo.Add("source", "tgw.jpg");
        JSONObject photoResult = api.Post("/" + AlbumId + "/photos", photo);

回答1:


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



来源:https://stackoverflow.com/questions/5452192/how-to-post-photo-to-album-in-facebook-graph-api-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!