问题
i wrote an application for facebook but i couldn't upload image to album that i created, code is in below, thanks for your help.
Facebook.FacebookAPI api = new Facebook.FacebookAPI(GetAccessToken());
Dictionary<string, string> album = new Dictionary<string, string>();
album.Add("name", "Test Album");
album.Add("message", "Message here!");
JSONObject result = api.Post("me/albums", album);
string AlbumId = result.Dictionary["id"].String;
Dictionary<string, string> photo = new Dictionary<string, string>();
photo.Add("message", "test Message");
photo.Add("source", "tgw.jpg");
JSONObject photoResult = api.Post("/" + AlbumId + "/photos", photo);
回答1:
Does this works for you?
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);
Taken from here
来源:https://stackoverflow.com/questions/5452192/how-to-post-photo-to-album-in-facebook-graph-api-asp-net