【问题标题】:How to post photo to album in facebook graph api Asp.NET如何在 facebook graph api Asp.NET 中将照片发布到相册
【发布时间】:2011-03-27 20:29:49
【问题描述】:

我为 facebook 编写了一个应用程序,但我无法将图像上传到我创建的相册, 代码在下面,感谢您的帮助。

        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);

【问题讨论】:

    标签: asp.net facebook-graph-api facebook-c#-sdk


    【解决方案1】:

    这对你有用吗?

    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);
    

    取自here

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-21
    相关资源
    最近更新 更多