【问题标题】:STTwitterAPI to pull number of tweets,followers and following?STTwitterAPI 来获取推文、关注者和关注者的数量?
【发布时间】:2014-08-23 17:43:23
【问题描述】:

我正在尝试在我的应用程序中创建个人资料以仅显示他的 Twitter 个人资料。到目前为止,我确实有时间线工作,但我没有推文、追随者和追随者的数字计数器。我很确定我可以使用我的代码看起来像但不知道如何使用的东西,有什么帮助吗?谢谢

代码:

STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@"ConsumerKey"
                                                        consumerSecret:@"consumerSecret"];

[twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {

    [twitter getUserTimelineWithScreenName:@"MikesiOSHelp"
                              successBlock:^(NSArray *statuses) {

                                  self.twitterFeed = [NSMutableArray arrayWithArray:statuses];

                                  [self->tableView reloadData];

                              } errorBlock:^(NSError *error) {

                                  NSLog(@"%@", error.debugDescription);

                              }];

} errorBlock:^(NSError *error) {

    NSLog(@"%@", error.debugDescription);

}];

【问题讨论】:

  • 控制台说什么?
  • 没什么,我贴的代码是获取TimeLine,而不是推文、关注者和关注者。

标签: ios objective-c twitter


【解决方案1】:

您应该查看他们的demo application

您在 CLI 演示中查找用户关注者的请求是 explicitly covered

typedef void (^AllFollowersBlock_t)(NSArray *allFollowers);

void getFollowers(STTwitterAPI *twitter,
                  NSString *screenName,
                  NSMutableArray *followers,
                  NSString *cursor,
                  AllFollowersBlock_t allFollowersBlock) {

    if(followers == nil) followers = [NSMutableArray array]; 

    NSMutableDictionary *md = [NSMutableDictionary dictionary];
    md[@"screen_name"] = screenName;
    if(cursor) md[@"cursor"] = cursor;
    md[@"skip_status"] = @"1";
    md[@"include_user_entities"] = @"0";

    [twitter getResource:@"followers/list.json"
           baseURLString:kBaseURLStringAPI_1_1
              parameters:md
   downloadProgressBlock:^(id json) {
       //
   } successBlock:^(NSDictionary *rateLimits, id response) {

       NSArray *users = nil;
       NSString *previousCursor = nil;
       NSString *nextCursor = nil;

       if([response isKindOfClass:[NSDictionary class]]) {
           users = [response valueForKey:@"users"];
           previousCursor = [response valueForKey:@"previous_cursor_str"];
           nextCursor = [response valueForKey:@"next_cursor_str"];
       }

       NSLog(@"-- users: %@", @([users count]));
       NSLog(@"-- previousCursor: %@", previousCursor);
       NSLog(@"-- nextCursor: %@", nextCursor);

       [followers addObjectsFromArray:users];

       if([nextCursor integerValue] == 0) {
           allFollowersBlock(followers);
           return;
       }

       /**/

       NSString *remainingString = [rateLimits objectForKey:@"x-rate-limit-remaining"];
       NSString *resetString = [rateLimits objectForKey:@"x-rate-limit-reset"];

       NSInteger remainingInteger = [remainingString integerValue];
       NSInteger resetInteger = [resetString integerValue];
       NSTimeInterval timeInterval = 0;

       if(remainingInteger == 0) {

           NSDate *resetDate = [[NSDate alloc] initWithTimeIntervalSince1970:resetInteger];
           timeInterval = [resetDate timeIntervalSinceDate:[NSDate date]] + 5;

       }

       NSLog(@"-- wait for %@ seconds", @(timeInterval));

       dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeInterval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

           getFollowers(twitter, screenName, followers, nextCursor, allFollowersBlock);

       });

   } errorBlock:^(NSError *error) {
       NSLog(@"-- error: %@", error);
   }];
}

【讨论】:

    猜你喜欢
    • 2013-07-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-11
    • 2014-01-06
    • 1970-01-01
    • 2014-08-13
    • 1970-01-01
    • 2019-03-07
    相关资源
    最近更新 更多