问题
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?
Here is my code :
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);
The access token, picture URI and create new event is working fine but not picture.
回答1:
First you need to realise there are 2 types of pictures for a Facebook event. The old style picture and the new Cover Photo.
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);
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");
来源:https://stackoverflow.com/questions/17024068/facebook-c-sharp-sdk-create-event-with-picture