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

发布于 2024-10-03 05:43:03 字数 349 浏览 2 评论 0原文

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

此代码上传失败

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后eg是否自 2024-10-10 05:43:03

这是取自我的一个单元测试的代码,该测试包含在 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文