首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >STTwitterAPI拉动推文、关注者和跟随者的数量?

STTwitterAPI拉动推文、关注者和跟随者的数量?
EN

Stack Overflow用户
提问于 2014-08-24 01:43:23
回答 1查看 84关注 0票数 0

我正在尝试在我的应用程序中创建一个配置文件,以便只显示他的twitter配置文件。到目前为止,我确实有工作的时间线,但我没有推文,追随者和关注的数字计数器。我很确定我可以使用我的代码,但不知道如何使用,有什么帮助吗?谢谢

代码:

代码语言:javascript
复制
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);

}];
EN

回答 1

Stack Overflow用户

发布于 2014-08-24 02:05:18

你应该看看他们的demo application

您查找用户关注者的请求在命令行界面演示中为explicitly covered

代码语言:javascript
复制
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);
   }];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25464669

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档