2014/05/24

[Twitter][iOS][Objective-C]followerを取得する

iOS上でtwitter frameworkを使ってログイン者のfollowerを取得するにはどうすればいいだろうか?

TWRequest *tWRequest;
    ACAccount *acAccount;
    NSNumber *cursor = [NSNumber numberWithInteger:-1];
    tWRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.twitter.com/1.1/followers/list.json"]
                                               parameters:@{
                                                            @"user_id":[acAccount valueForKeyPath:@"properties.user_id"],
                                                            @"count":@"100",
                                                            @"cursor":[cursor stringValue]
                                                            }
                                            requestMethod:TWRequestMethodGET];
    tWRequest.account = acAccount;
    
    
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0);
    dispatch_async(queue, ^{
        [tWRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error){
            if(!error){

                NSDictionary *dictJSON = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:nil];

                cursor = (NSNumber *)[dictJSON objectForKey:@"previous_cursor"];
                NSArray *users = (NSArray *)[dictJSON objectForKey:@"users"];
                dispatch_async(dispatch_get_main_queue(),^{
                    tWRequest = nil;
                });
            }
        }];
    });
こうやってまとめておけば便利かなと。

0 コメント:

コメントを投稿