Closed Naville closed 8 years ago
I understand that you are trying to get followers in a command line app.
If so, check the following example https://github.com/nst/STTwitter/blob/master/demo_cli/followers/main.m
If not, please give me more context.
Many thanks for your time.
int main(int argc, const char * argv[])
{
__block NSMutableArray *followersIDs = [NSMutableArray array];
__block STTwitterAPI *t = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:ConsumerKey consumerSecret:ConsumerSecret];
[t verifyCredentialsWithUserSuccessBlock:^(NSString *username, NSString *userID) {
[t getFollowersForScreenName:@"__PAGEZERO" successBlock:^(NSArray* followers) {
[followersIDs addObjectsFromArray:followers];
NSLog(@"Follower List:%@",followers);
}errorBlock:^(NSError* error){
NSLog(@"--1 %@", error);
}];
} errorBlock:^(NSError *error) {
NSLog(@"--1 %@", error);
}];
if(followersIDs.count==0){
[[NSRunLoop currentRunLoop] run];
}
exit(0);
}
Without the RunLoop part,the program quit without logging out anything. Put it back,the process stuck after printing out the followers.
And I also tried open a new project to flush the environment issue,still the same problem
Note that you need to use blessed consumer tokens to get the followers IDs.
I've just tried the "followers.m" example with Twitter for iPhone credentials and I get the requested data.
The following code
#import <Foundation/Foundation.h>
#import "STTwitter.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
__block NSMutableArray *followersIDs = [NSMutableArray array];
__block STTwitterAPI *t = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:TWITTER_FOR_IPHONE_KEY consumerSecret:TWITTER_FOR_IPHONE_SECRET];
[t verifyCredentialsWithUserSuccessBlock:^(NSString *username, NSString *userID) {
[t getFollowersForScreenName:@"__PAGEZERO" successBlock:^(NSArray* followers) {
[followersIDs addObjectsFromArray:followers];
NSLog(@"Follower List:%@", [followers valueForKey:@"id"]);
} errorBlock:^(NSError* error){
NSLog(@"--1 %@", error);
}];
} errorBlock:^(NSError *error) {
NSLog(@"--2 %@", error);
}];
[[NSRunLoop currentRunLoop] run];
}
return(0);
}
does print
2015-12-22 23:04:08.025 followers[37880:1147574] Follower List:(
37889864,
2266178594,
178671108,
86315276,
562750823,
826966795,
2995540044,
1659810062,
16604957,
207147193,
192749227,
131282204,
795470076,
64261195,
310753146,
2521729640,
175265857,
2369503294,
525206194,
2859955145,
3131655941,
2790323576,
3426739588,
499987130,
325560607,
52738645,
2650605524,
4263498351,
4553383332,
4456212492,
4515864793,
4472051592,
4485142993,
4330876392,
3131682971,
4308548243,
4112935512
)
well,I guess it's some problem in my environment. (Which I have no idea) Thanks
I got the requested data as well. The problem is I need to runloop it twice since it did nothing,or receive an empty array for the first time
Clean run. Doesn't do anything,neither success,fail was called. After RunLoop was added. The first run still doesn't do anything,but starts to respond from the second time