【问题标题】:How to get media from TwitterKit?如何从 TwitterKit 获取媒体?
【发布时间】:2019-04-15 22:38:33
【问题描述】:

我使用以下代码获取公众号的订阅源,但是无法获取图片、视频、gif等媒体。

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];
}];

这里我得到了 TWTRTweet 数组,但它不包含任何媒体。

帮帮我。

【问题讨论】:

    标签: ios objective-c twitter twitterkit


    【解决方案1】:

    您可以使用以下代码中的私有成员和类。

    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
             }
    
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-15
      • 1970-01-01
      • 2014-02-05
      • 1970-01-01
      • 1970-01-01
      • 2021-01-29
      • 2020-02-14
      • 2015-08-08
      相关资源
      最近更新 更多