Get image of tweet in Rest API in Swift



I want to display the (optional) image of the tweets in the Home-Timeline but i´m not able to find the right keyword. I also looked at this documentation about entities in tweets. I created the entities dictionary and an media dictionary in the entities and requested the media_url but its nil. My code:
let tweet = self.dataSource[row] as! NSDictionary let entitiesDictionary = tweet.objectForKey("entities") as! NSDictionary print("after entities") let mediaDictionary = entitiesDictionary.objectForKey("media") as! NSDictionary print("after media") if mediaDictionary.objectForKey("media_url") != nil { print("Pic there") let picURL = NSURL(string: (userDictionary["media_url_https"] as! String).stringByReplacingOccurrencesOfString("_normal", withString: "_bigger", options: NSStringCompareOptions.RegularExpressionSearch, range: nil)) let image = NSData(contentsOfURL: picURL!) cell.tweetImage.image = UIImage(data: image!) }


Are you using Fabric, or some other library, for accessing the Tweets?


@andypiper Fabric (and the RestAPI):slight_smile:


Cool. Let me move this over to the Twitter Kit category under Fabric so can receive attention from people there.


@andypiper should I take the url in the entities dic and then load the pic from the url?


That would be my approach yes.


@andypiper I´m not finding the url of the optional image. I looked at the docs and tried some. For example: let tweet = self.dataSource[row] as! NSDictionary let mediaUrl = tweet.objectForKey("media_url") as? NSURL if mediaUrl != nil { print("!!!!media url ist da: \(mediaUrl)") }
Can you help me?