我正在编写一个将多张照片上传到特定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);
}
答案 0 :(得分:2)
此链接适用于我: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")) } })
);