如何在Facebook图形API Asp.NET中将照片发布到相册 [英] How to post photo to album in facebook graph api Asp.NET
本文介绍了如何在Facebook图形API Asp.NET中将照片发布到相册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为Facebook编写了一个应用程序,但无法将图像上传到我创建的相册中, 代码在下面,谢谢您的帮助.
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);
推荐答案
这对您有用吗?
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);
来自此处
这篇关于如何在Facebook图形API Asp.NET中将照片发布到相册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文