开发者

C# facebook graph / How to upload to album id

开发者_如何转开发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);

this code is upload failed


This is code take from one of my unit tests which is included in the source of the SDK. This is how you would upload a photo:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜