Facebook C#SDK,创建图片事件 [英] Facebook C# SDK, Create Event With Picture
问题描述
我想创建一个事件,但我只是不知道如何更改事件图片。我知道这是一个非常古老的问题,但是我仍然找不到任何解决方案,我很快放弃了...请至少告诉我这是Facebook或其他任何错误?
i want to create a event but i just no idea how to change the event picture. I knew this is very old question but still i can't find any solution yet and i'm giving up soon... please at least tell me is this bugs from Facebook or anything else?
这是我的代码:
Facebook.FacebookClient fb = new Facebook.FacebookClient(accessToken);
Dictionary<string, object> ev = new Dictionary<string, object>();
ev.Add("name", model.name);
ev.Add("start_time", model.start_time);
ev.Add("end_time", model.end_time);
ev.Add("description", model.description);
ev.Add("location", model.location);
ev.Add("privacy_type", model.privacy_type);
ev.Add("is_date_only", model.is_date_only);
//ev.Add("picture", "@https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/c0.0.50.50/p50x50/601514_10151470263757778_629077232_s.jpg"); //NOT WORKING
//ev.Add("source", "@https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/c0.0.50.50/p50x50/601514_10151470263757778_629077232_s.jpg"); //NOT WORKING
//ev.Add("picture", HttpUtility.UrlEncode("@https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/c0.0.50.50/p50x50/601514_10151470263757778_629077232_s.jpg")); //NOT WORKING
//ev.Add("source", HttpUtility.UrlEncode("https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/c0.0.50.50/p50x50/601514_10151470263757778_629077232_s.jpg")); //NOT WORKING
//ev.Add("picture", model.picture); //NOT WORKING
object EventId = fb.Post("/me/events", ev);
Dictionary<string, string> p = (new JavaScriptSerializer()).Deserialize<Dictionary<string, string>>(EventId.ToString());
Dictionary<string, object> pic = new Dictionary<string, object>();
//pic.Add("source", model.picture); //NOT WORKING
//pic.Add("picture", HttpUtility.UrlEncode("https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/c0.0.50.50/p50x50/601514_10151470263757778_629077232_s.jpg")); //NOT WORKING
//pic.Add("source",HttpUtility.UrlEncode("https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/c0.0.50.50/p50x50/601514_10151470263757778_629077232_s.jpg")); //NOT WORKING
object objPicture = fb.Post("/" + p["id"] + "/picture", pic);
访问令牌,图片URI和创建新事件正常工作但不是图片。
The access token, picture URI and create new event is working fine but not picture.
推荐答案
首先你需要意识到Facebook事件有两种类型的图片。旧的风格图片和新的封面照片。
First you need to realise there are 2 types of pictures for a Facebook event. The old style picture and the new Cover Photo.
如果你想做旧的风格图片,你不给它一个url,你需要传递它的数据在图片参数的参数之一。
If you want to do the old style picture you don't give it a url, you need to pass it the data in one of the arguments to the picture argument.
var arguments = new Dictionary<string, object>();
var mediaSource = new FacebookMediaObject
{
FileName = "image.jpg",
ContentType = "image/jpeg"
};
mediaSource.SetValue(webClient.DownloadData(url));
arguments.Add("picture", mediaSource);
Object value = client.Post(String.Format("/{0}/events/", "facebook_pageId_here"), arguments);
如果要更新该图片最好做
if you want to update that picture it is best to do
var arguments = new Dictionary<string, object>();
var mediaSource = new FacebookMediaObject
{
FileName = "image.jpg",
ContentType = "image/jpeg"
};
mediaSource.SetValue(webClient.DownloadData(url));
arguments.Add("source", mediaSource);
Object value = client.Post(String.Format("/{0}/picture/", "event_id_here"), arguments);
现在,如果你想做封面照片,我唯一能够工作的东西是通过传递一个url到cover_url参数。
Now if you want to do the cover photo, the only thing I have managed to get working so far is by passing in a url to the cover_url parameter.
arguments.Add("cover_url", "http://domain.com/image.jpg");
这篇关于Facebook C#SDK,创建图片事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!