简体   繁体   English

您如何缩短使用Twitter API(php)发送的推文中的url?

[英]How do you shorten urls in tweets sent using the Twitter API (php)?

I'm using the Twitter API (php) and when posting statuses through it, it doesn't seem to use t.co to shorten urls. 我正在使用Twitter API(php),并通过它发布状态时,它似乎并未使用t.co来缩短网址。 I read that t.co is only used when posting a tweet and not for outside apps or websites, but that makes it sound like it isn't a "public use" url shortener (eg bit.ly) but that it was only for use within Twitter - I didn't think this meant that it cannot be used via the API. 我读到t.co仅在发布推文时使用,不适用于外部应用程序或网站,但这听起来像不是“公共使用” URL缩短器(例如bit.ly),但它仅用于在Twitter中使用-我认为这并不意味着无法通过API使用它。

I still can't find whether this is the case or not because, on the one hand, my URLs aren't getting shortened, but on the other hand I've found discussions and even stackoverflow questions like this which say that urls will be shortened when using the API, no matter what, even if they are shorter than the url shortened length (I believe it is 23 chars at the moment). 我仍然找不到这种情况,因为,一方面,我的URL并没有缩短,但另一方面,我发现了讨论甚至是类似 stackoverflow的问题,这些问题说URL将是使用API​​时会缩短,无论如何,即使它们比url缩短的长度都短(我相信目前为23个字符)。

Could somebody please clarify this for me? 有人可以帮我澄清一下吗? And if it is the case that you cannot shorten URLs with t.co when using the twitter API, could somebody recommend me a good url shortening service/api that has a PHP wrapper? 如果是在使用twitter API时无法使用t.co缩短URL的情况,有人可以推荐我一个具有PHP包装程序的优质URL缩短服务/ api吗?

Thank you for your time. 感谢您的时间。

Check out twitters dev docs on t.co links . 在t.co链接上查看twitters dev文档 The FAQ section on that page covers your question. 该页面上的常见问题解答部分涵盖了您的问题。

When are links wrapped with t.co? 什么时候用t.co包裹链接? Do I need to make an extra API call? 我是否需要进行额外的API调用? Links will be wrapped when Twitter receives a Tweet using POST statuses/update or a direct message using POST direct_messages/new. 当Twitter收到使用POST状态/更新的推文或使用POST direct_messages / new的直接消息时,链接将被包装。 The wrapped link will be contained in the response to a successful request. 包装的链接将包含在对成功请求的响应中。 You don't need to make any extra API calls. 您不需要进行任何额外的API调用。

Will t.co-wrapped links always be the same length? t.co包裹的链接会始终保持相同的长度吗? The maximum length of t.co URLs will change over time. t.co URL的最大长度将随着时间而变化。 Issue a request daily to GET help/configuration and examine the fields short_url_length and short_url_length_https to determine the current maximum length of wrapped URLs. 每天向GET帮助/配置发出请求,并检查short_url_length和short_url_length_https字段以确定当前已包装URL的最大长度。 We do not expect these values to change often. 我们认为这些价值观不会经常改变。

It is important to note that you won't necessarily know the length of a t.co URL before posting. 重要的是要注意,发布前不一定知道t.co URL的长度。 Consider the short_url_length field a maximum possible length for a t.co-wrapped link. 考虑short_url_length字段是t.co包裹的链接的最大可能长度。 When designing a Tweet entry box, it's best to consider all URLs as equalling the maximum possible short_url_length. 设计推文输入框时,最好考虑所有URL等于最大可能的short_url_length。

Whenever you come across conflicting information and are unsure what the actual case is, the API docs should always have the final say. 每当您遇到冲突的信息并且不确定实际情况是什么时,API文档应该始终拥有最终决定权。 Normally they will be the most up to date source of information. 通常,它们将是最新的信息源。

All links submitted within Tweets and direct messages, regardless of length, will eventually be wrapped with t.co. Tweets和直接消息中提交的所有链接(无论长度如何) 最终都将被t.co包裹。

Emphasis mine. 强调我的。 This line from the docs subtlety hints that there could be delays in the shortening process. docs的这一小句提示暗示缩短过程可能会有所延迟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM