ios Twitter api 文本字段值被截断

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38717816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:49:13  来源:igfitidea点击:

Twitter api text field value is truncated

iosjsonswiftapitwitter

提问by shesh nath

why text field value is truncated and how can i get complete value. As of now i am trying to get text field value like below

为什么文本字段值被截断以及如何获得完整的值。截至目前,我正在尝试获取如下所示的文本字段值

do {
       if let responseObject = try NSJSONSerialization.JSONObjectWithData(response, options: []) as? [String:AnyObject],
           arrayStatuses = responseObject["statuses"] as? [[String:AnyObject]] {
               let arrTweets:NSMutableArray = NSMutableArray()
               for status in arrayStatuses {
                   let text = status["text"]!
                   print(status["text"]!)
               }
       }
}

output is

输出是

RT @WarfareWW: #Russia/#India may hold launches of BrahMos cruise missiles from Su-30MKI vs sea/grnd trgts at the end of this year https://…

RT @WarfareWW:#Russia/#India 可能会在今年年底从 Su-30MKI vs sea/grnd trgts 发射布拉莫斯巡航导弹 https://...

three dots at the end of line. i need to print complete text without truncation.

行尾的三个点。我需要打印完整的文本而不被截断。

Twitter sample search result JSON Data

Twitter 示例搜索结果 JSON 数据

{
      "created_at": "Mon Aug 01 08:07:43 +0000 2016",
      "id": 760024194079916032,
      "id_str": "760024194079916032",
      "text": "RT @khalidasopore: #KEXIT #KASHEXIT #KashmirKillings #Inida #Pakistan Just trend it my dear Indians to save #Kashmir from Pak Goons https:/…",
      "truncated": false
}

回答by Ely

The Twitter API has been changed recently, to support new rules regarding the 280 characters limit.

Twitter API 最近已更改,以支持有关 280 个字符限制的新规则。

  1. To get the full text of the tweet, add parameter tweet_modewith value extendedto your request parameters.
  2. Field textin the JSON response has been replaced by full_text
  1. 要获取推文的全文,请将tweet_mode带值的参数添加extended到您的请求参数中。
  2. textJSON 响应中的字段已被替换为full_text

More info here: https://dev.twitter.com/overview/api/upcoming-changes-to-tweets

更多信息:https: //dev.twitter.com/overview/api/upcoming-changes-to-tweets

回答by pterry26

The status in this example is a retweet, and the text for retweets will be truncated to 140 characters even after including tweet_mode=extended. The full text of the original tweet is in the retweeted_statusfield of the JSON response. Here's what you want:

本例中的状态是转推,转推的文本即使在包含tweet_mode=extended. 原始推文的retweeted_status全文在 JSON 响应字段中。这是你想要的:

let text = status["retweeted_status"]["full_text"].

let text = status["retweeted_status"]["full_text"].

Keep in mind that you should still include tweet_mode=extendedin your request.

请记住,您仍应将其包含tweet_mode=extended在您的请求中。