开发者

facebook c# sdk: Add/edit event with newlines in description

I am trying to edit events on facebook pages. The SDK works fine, but I have one problem.

Whenever there are newlines in the description (\r\n), they get posted to facebook. So I get event bodies like:

New event!\r\nWelcome to the event.

instead of

New event!

Welcome to the event.

looking in the result of a graph get to the event, I see that the newlines are double escaped, an开发者_如何学God looks like this:

...

"name": "TEST EVENT",

"description": "New event!\\r\\nWelcome to the event.",

"start_time": "2011-03-24T00:00:00"

...

I've tried any and all possible solutions I can think of, but to no avail. I've been reduced to replacing newlines with " * " just to separate sentences...

The text comes as a string in an object, and is transferred to a JsonObject.

JsonObject owner = new JsonObject { .... };
JsonObject evt = new JsonObject();
evt.Add("id", eventId);
evt.Add("owner", owner);
evt.Add("name", eventItem.Name);
evt.Add("updated_time", eventItem.Updated.ToString("o"));
evt.Add("description", eventItem.Description);
evt.Add("start_time", eventItem.StartDate.ToString("o"));
evt.Add("end_time", eventItem.EndDate.ToString("o"));
...
var fbc = new FacebookClient(internalObject.AccessToken);
result = (bool) fbc.Post(evt);

Any Ideas?

EDIT:

Workaround. I made a change to FacebookUtils.ToJsonQueryString. This works, but I guess it might be a bug in the SDK?

Looks like Facebook doesnt support standard Json escaping of newlines in event?

internal static string ToJsonQueryString(IDictionary<string, object> dictionary)
{
   ...

   jsonValue = jsonValue.Replace("\\n", "\n").Replace("\\r", "\r");

   if (!String.IsNullOrEmpty(jsonValue))
   {
      var encodedValue = UrlEncode(jsonValue);
      sb.AppendFormat(CultureInfo.InvariantCulture, "{0}={1}", key, encodedValue);

   ...
   return sb.ToString();
}

This change makes \r\n in the returned querystring look like %0d%0a instead of %5cr%5cn, which is what facebook accepts.

Royan


Fixed as of version SDK 5.0.8 - 25. march


This works:

Use this: <center></center>

Instead of a br or a newline, etc. You can only do one in a row (ie. you can't increase the spacing).


Is there any reason why you wouldn't use:

{
    "name": "TEST EVENT",
    "description": "New event!<br/>Welcome to the event.",
    "start_time": "2011-03-24T00:00:00"
} 

jsonlint validates it...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜