有没有人知道Twitter的TwitterKit是否仍然只为推文提取140个字符而不是更新的计数?我将文本放入具有动态属性的UILabel中,该属性应该自行调整大小,但我仍然会截断推文。
对于更好奇的人,我也使用以下代码来获取JSON:
public func fetchTweets(_ handler: @escaping ([Tweet]) -> Void) {
fetch { results in
var tweets = [Tweet]()
var tweetArray: NSArray?
if let dictionary = results as? NSDictionary {
if let tweets = dictionary[TwitterKey.tweets] as? NSArray {
tweetArray = tweets
} else if let tweet = Tweet(data: dictionary) {
tweets = [tweet]
}
} else if let array = results as? NSArray {
tweetArray = array
}
if tweetArray != nil {
for tweetData in tweetArray! {
if let tweet = Tweet(data: tweetData as? NSDictionary) {
tweets.append(tweet)
}
}
}
handler(tweets)
}
}
public func fetch(_ handler: @escaping (PropertyList?) -> Void) {
performTwitterRequest("GET", handler: handler)
}
func performTwitterRequest(_ method: String, handler: @escaping (PropertyList?) -> Void) {
Twitter.sharedInstance().sessionStore.session()?.userID {
let client = TWTRAPIClient()
let jsonExtension = (self.requestType.range(of: Constants.JSONExtension) == nil) ? Constants.JSONExtension : ""
let url = "\(Constants.twitterURLPrefix)\(self.requestType)\(jsonExtension)"
var clientError : NSError?
let request = client.urlRequest(withMethod: method, url: url, parameters: parameters, error: &clientError)
sendTwitterRequest(client: client, request: request, handler: handler)
}
func sendTwitterRequest(client: TWTRAPIClient, request: URLRequest, handler: @escaping (PropertyList?) -> Void) {
client.sendTwitterRequest(request) { (response, responseData, error) -> Void in
if let err = error {
print("Error: \(err.localizedDescription)")
}
var propertyListResponse: PropertyList?
if responseData != nil {
propertyListResponse = try? JSONSerialization.jsonObject(with: responseData!, options: .mutableLeaves)
if propertyListResponse == nil {
let error = "Couldn't parse JSON response."
self.log(error)
propertyListResponse = error
}
} else {
let error = "No response from Twitter."
self.log(error)
propertyListResponse = error
}
self.synchronize {
self.captureFollowonRequestInfo(propertyListResponse)
}
handler(propertyListResponse)
}
}
答案 0 :(得分:1)
我建议从一个类似的问题看一下这个答案。 https://stackoverflow.com/a/40429448/8930099
答案 1 :(得分:1)
看起来您手动调用Twitter API端点来获取推文数组,因此您需要在调用中添加tweet_mode=extended
参数,以便获取最多280个字符的更长推文。