How to get media from TwitterKit?

84 views Asked by At

I have used the following code to get the feeds of the public account, however, I am unable to get media such as images, videos, gifs etc.

TWTRAPIClient *APIClient = TWTRAPIClient.clientWithCurrentUser;
TWTRUserTimelineDataSource *newArray = [[TWTRUserTimelineDataSource alloc] initWithScreenName:@"TomCruise" APIClient:APIClient];

[newArray loadPreviousTweetsBeforePosition:@"0" completion:^(NSArray<TWTRTweet *> * _Nullable tweets, TWTRTimelineCursor * _Nullable cursor, NSError * _Nullable error) {
    for (int count=0; count<tweets.count; count++) {
        NSLog(@"tweet json is == \n%@",[tweets[count] tweetID]);
        NSLog(@"tweet text is == \n%@",[tweets[count] text]);
        [self.twitterarray addObject:[tweets[count] text]];
    }

    [self reloadCollectionView];
}];

Here I got the array of TWTRTweet array but it doesn't contain any media.

Help me.

1

There are 1 answers

0
Salman Ghumsani On BEST ANSWER

You can use private member and classes from the following code.

TWTRAPIClient *APIClient = TWTRAPIClient.clientWithCurrentUser;
    //TWTRUserTimelineDataSource *newArray =  [[TWTRUserTimelineDataSource alloc] initWithScreenName:@"TomCruise" APIClient:APIClient];
    TWTRUserTimelineDataSource *newArray= [[TWTRUserTimelineDataSource alloc] initWithScreenName:@"TomCruise" userID:nil APIClient:APIClient maxTweetsPerRequest:10 includeReplies:true includeRetweets:true];
    [newArray loadPreviousTweetsBeforePosition:@"0" completion:^(NSArray<TWTRTweet *> * _Nullable tweets, TWTRTimelineCursor * _Nullable cursor, NSError * _Nullable error) {
        for (int count=0; count<tweets.count; count++) {
            NSLog(@"tweet text is == %@ \n",[tweets[count] text]);
            NSLog(@"media %@",[[tweets[count] valueForKey:@"media"] valueForKey:@"mediaUrl"]);//_mediaUrl
         }

}];