使用 Tweetsharp 更新 twitter 状态时是否应该使用 HtmlEncode?

发布于 2024-09-01 12:21:05 字数 337 浏览 3 评论 0原文

我正在使用 tweetsharp 发送推文。

var response = _twitter.AuthenticateWith(item.TwitterToken, item.TwitterSecret)
    .Statuses().Update(HttpUtility.HtmlEncode(item.Tweet)).AsXml().Request().Response;

您可能已经注意到,上面我对消息进行了 HtmlEncoding,这可能会导致消息超过 140 个字符?有必要以这种方式对消息进行编码吗? tweetsharp 或 twitter 是否建议先发送消息而不进行编码?

I am using tweetsharp to send tweets.

var response = _twitter.AuthenticateWith(item.TwitterToken, item.TwitterSecret)
    .Statuses().Update(HttpUtility.HtmlEncode(item.Tweet)).AsXml().Request().Response;

As you may have noticed, above I am HtmlEncoding the message this can cause the message to go over 140 chars? Is encoding the message this way necessary? Does tweetsharp or twitter recommend sending messages without encoding first?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

澉约 2024-09-08 12:21:05

TweetSharp 将为您处理所有编码。只需将您要发布的字符串传递给它即可。

TweetSharp will handle all of the encoding for you. Just pass it the string you want to post.

只涨不跌 2024-09-08 12:21:05

来自此处

Twitter API 支持 UTF-8
编码。请注意角度
括号(“<”和“>”)是
实体编码以防止跨站
针对 Web 嵌入的脚本攻击
JSON API 输出的使用者。这
生成的编码实体确实很重要
接近 140 个字符的限制。什么时候
请求 XML,响应为 UTF-8
编码。符号和字符
超出标准 ASCII 范围
可以转换为 HTML 实体

这对我来说,您确实应该确保您的输出被编码(不一定是 HTML 编码)为 UTF-8。您是否尝试过UTF-8编码然后提交,然后查看“特殊”字符的输出?

From here:

The Twitter API supports UTF-8
encoding. Please note that angle
brackets ("<" and ">") are
entity-encoded to prevent Cross-Site
Scripting attacks for web-embedded
consumers of JSON API output. The
resulting encoded entities do count
towards the 140 character limit. When
requesting XML, the response is UTF-8
encoded. Symbols and characters
outside of the standard ASCII range
may be translated to HTML entities.

This says to me that you should indeed make sure that your output is encoded (not necessarily HTML encoded) to UTF-8. Have you tried to UTF-8 encode and then submit, then look at the output of "special" characters?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文