0

我想创建一个活动,但我不知道如何更改活动图片。我知道这是一个非常古老的问题,但我仍然找不到任何解决方案,我很快就会放弃......请至少告诉我这是来自 Facebook 的错误还是其他什么?

这是我的代码:

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 和创建新事件工作正常,但图片不行。

4

1 回答 1

0

首先,您需要了解 Facebook 活动有两种类型的图片。旧风格图片和新封面照片。

如果你想做旧式图片,你不给它一个 url,你需要将其中一个参数中的数据传递给图片参数。

        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);

如果您想更新该图片,最好这样做

        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 参数。

        arguments.Add("cover_url", "http://domain.com/image.jpg");
于 2013-07-09T14:49:09.593 回答