简体   繁体   English

C#Facebook图形/如何上传到相册ID

[英]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. 这是我的一个单元测试中的代码,该单元测试包含在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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM