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

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

我正在编写一个将多张照片上传到特定 Facebook 相册的应用程序。 当前代码不使用批量请求上传照片。

我的问题是:如何批量上传多张照片?

当前代码:

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

这个 link 对我有用:here

示例代码:

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