C#facebook graph /如何上传到相册ID

1 c# facebook facebook-graph-api

Dictionary<string, object> newPhotoParam = new Dictionary<string, object>();

newPhotoParam.Add("access_token", _app.AccessToken);
newPhotoParam.Add("source", "e:\\sample.jpg");
newPhotoParam.Add("message", "test photo upload");

_app.Api("/"+ albumID +"/photos", newPhotoParam, HttpMethod.Post);
Run Code Online (Sandbox Code Playgroud)

此代码上传失败

Nat*_*ten 6

这是我的一个单元测试的代码,它包含在SDK的源代码中.这是你上传照片的方式:

        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);
Run Code Online (Sandbox Code Playgroud)