C# facebook 图表/如何上传到专辑 id [英] C# facebook graph / How to upload to album id
本文介绍了C# facebook 图表/如何上传到专辑 id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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);
此代码上传失败
推荐答案
这是从我的一个单元测试中提取的代码,它包含在 SDK 的源代码中.这是您上传照片的方式:
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.TestsinReleasemonkey.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);
这篇关于C# facebook 图表/如何上传到专辑 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文