2

现在,当用户选择要通过 Twitter 分享的文章时,我想提供链接以及 URL 的标题,但我很难弄清楚链接在 Twitter 中的重要性。

通过 iOS API 与 Twitter 共享的链接是否计为 URL 的完整长度,或者它是一个 URL,给定一个特殊的规则/长度?如果是这样,我如何计算长度。我读过几篇文章说链接被认为是 22 个字符长,但最近从 20 个字符变了。如果它再次更改怎么办?

那么一个链接有多长呢?一旦我弄清楚了,我应该用140 - link length多少个字符来计算标题?

4

1 回答 1

1

Per the twitter docs, all URL's are shortened using their t.co service - including those submitted via SLComposeViewController. The docs say that if you attempt to add a long URL to a SLComposeViewController it will succeed or fail based on available space, and that it is the shortened URL that is used when making this decision.

They don't give you a character count but they do tell you if what you're trying to add will fit.

Excerpt from the linked Twitter docs, emphasis mine:

Below is an example of the above steps. Note that the methods for setting initial content respond with Boolean values; this allows you, the developer, to not have to worry about the current count of characters in the body of the Tweet that you are initializing. If the method returns YES, there was enough room to add the content. If the method returns NO, the content you attempted to add would result in a Tweet longer than 140 characters. The logic for character counting also takes into effect the current number of characters required for t.co URL wrapping.

I haven't tried but you could likely determine the number of characters available after first adding your URL by iteratively calling setInitialText: with a string with decreasing character count, starting with 140 characters.

于 2013-10-31T21:06:32.747 回答