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.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);
这篇关于C#Facebook的图形/如何上传到相册ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文