简体   繁体   English

使用facebook c#sdk在批处理请求中将多张照片上传到facebook相册

[英]Upload multiple photos to facebook album in Batch Request with facebook c# sdk

I'm writing an application that uploads a multiple photos to a specific Facebook album. 我正在编写一个将多张照片上传到特定Facebook相册的应用程序。 the current code dose not uses batch request to upload the photos. 当前代码未使用批量请求上传照片。

My question is: how to upload mulitple photos in a batch request ? 我的问题是:如何在批量请求中上传多张照片?

current code: 当前代码:

JsonObject jasonObj = CreateAlbum(accessToken);

UploadPhoto(jo["id"].toString(""), accessToken, filename);

 public JsonObject CreateAlbum(string accessToken)
        {
            FacebookClient facebookClient = new FacebookClient(accessToken);
            Dictionary<string, object> albumParameters = new Dictionary<string, object>();
            albumParameters.Add("message", "My Album message");
            albumParameters.Add("name", "Album Name");
            JsonObject resul = facebookClient.Post("/me/albums", albumParameters) as JsonObject;
            return resul;
        }

    public void UploadPhoto(string AlbumId, string accessToken, string FullImagePath)
    {
        byte[] photo = File.ReadAllBytes(FullImagePath);

        FacebookApp app = new FacebookApp();
        dynamic parameters = new ExpandoObject();
        parameters.access_token = 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 = "top.jpg",
            ContentType = "image/jpeg",
        };
        mediaObject.SetValue(photo);
        parameters.source = mediaObject;

        dynamic result = app.Api(String.Format("/{0}/photos", AlbumId), parameters, HttpMethod.Post);
    }

This link worked for me: here 此链接对我有用: 在这里

sample code: 样例代码:

dynamic result = fb.Batch(
            new FacebookBatchParameter(HttpMethod.Post, "/me/photos", new Dictionary<string, object> { { "message", "picture 1 msg" }, { "pic1", new FacebookMediaObject { ContentType = "image/jpeg", FileName = "Tulips.jpg" }.SetValue(File.ReadAllBytes(@"C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg")) } }),
            new FacebookBatchParameter(HttpMethod.Post, "/me/photos", new Dictionary<string, object> { { "message", "picture 2 msg" }, { "pic2", new FacebookMediaObject { ContentType = "image/jpeg", FileName = "Penguins.jpg" }.SetValue(File.ReadAllBytes(@"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg")) } })
          );

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

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