facebook c#sdk:添加/编辑事件,描述中包含换行符 [英] facebook c# sdk: Add/edit event with newlines in description
问题描述
我正在尝试编辑Facebook页面上的事件. 该SDK可以正常运行,但是我有一个问题.
I am trying to edit events on facebook pages. The SDK works fine, but I have one problem.
只要描述中有换行符(\ r \ n),它们就会发布到Facebook. 所以我得到像这样的事件主体:
Whenever there are newlines in the description (\r\n), they get posted to facebook. So I get event bodies like:
新活动!\ r \ n欢迎参加活动.
New event!\r\nWelcome to the event.
代替
新活动!
欢迎参加活动.
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, and looks like this:
...
"name":"TEST EVENT",
"description":新事件!\\ r \\ n欢迎来到该事件.",
"start_time":"2011-03-24T00:00:00"
...
...
"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...
文本作为对象中的字符串出现,并被传输到JsonObject.
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);
有什么想法吗?
解决方法. 我对FacebookUtils.ToJsonQueryString进行了更改. 这行得通,但是我想这可能是SDK中的错误?
Workaround. I made a change to FacebookUtils.ToJsonQueryString. This works, but I guess it might be a bug in the SDK?
好像Facebook在事件中不支持标准的Json换行符转义吗?
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();
}
此更改使返回的查询字符串中的\ r \ n看起来像%0d%0a而不是Facebook接受的%5cr%5cn.
This change makes \r\n in the returned querystring look like %0d%0a instead of %5cr%5cn, which is what facebook accepts.
Royan
推荐答案
已从SDK 5.0.8版固定-3月25日.
Fixed as of version SDK 5.0.8 - 25. march
这篇关于facebook c#sdk:添加/编辑事件,描述中包含换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!