Search code examples
swifttwitter

Twitter APK only sending 140 characters?


Does anyone know if TwitterKit for iOS is still only fetching 140 characters for tweets instead of the updated count? I am putting text into a UILabel with dynamic properties that should resize itself but I am still getting truncated tweets.enter image description here

For the more curious, I am also using the following code to get the 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)
    }
}

Solution

  • It looks like you’re manually calling the Twitter API endpoint to fetch an array of Tweets, so you’ll need to add the tweet_mode=extended parameter to the call in order to fetch longer Tweets up to 280 characters.