在iOS上如何获取用户在Twitter上关注的关注者列表?

时间:2021-11-28 06:24:30

In my app I would like to send a direct message to Twitter friends to invite to use the app. In order to send a direct message I need the target person to follow the user. How ever I don't want to list all the followers but only the followers that the user is also following. Is there a way to get this list in iOS?

在我的应用程序中,我想向Twitter朋友发送一条直接消息,邀请他们使用该应用程序。为了发送直接消息,我需要目标人员跟随用户。我怎么不想列出所有关注者,只列出用户也关注的关注者。有没有办法在iOS中获取此列表?

Thanks

2 个解决方案

#1


5  

Use FHSTwitterEngine

#import "FHSTwitterEngine.h"

Add SystemConfiguration.framework

Write following code to your viewDidLoad(for oauth login)

将以下代码写入viewDidLoad(用于oauth登录)

UIButton *logIn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
logIn.frame = CGRectMake(100, 100, 100, 100);
[logIn setTitle:@"Login" forState:UIControlStateNormal];
[logIn addTarget:self action:@selector(showLoginWindow:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:logIn];

[[FHSTwitterEngine sharedEngine]permanentlySetConsumerKey:@"Xg3ACDprWAH8loEPjMzRg" andSecret:@"9LwYDxw1iTc6D9ebHdrYCZrJP4lJhQv5uf4ueiPHvJ0"];
[[FHSTwitterEngine sharedEngine]setDelegate:self];


 - (void)showLoginWindow:(id)sender {
UIViewController *loginController = [[FHSTwitterEngine sharedEngine]loginControllerWithCompletionHandler:^(BOOL success) {
    NSLog(success?@"L0L success":@"O noes!!! Loggen faylur!!!");
    [[FHSTwitterEngine sharedEngine]loadAccessToken];
    NSString *username = [FHSTwitterEngine sharedEngine].authenticatedUsername;
    NSLog(@"user name is :%@",username);
    if (username.length > 0) {
        [self listResults];
    }
}];
     [self presentViewController:loginController animated:YES completion:nil];
}
 - (void)listResults {

NSString *username = [FHSTwitterEngine sharedEngine].authenticatedUsername;
NSMutableDictionary *   dict1 = [[FHSTwitterEngine sharedEngine]listFriendsForUser:username isID:NO withCursor:@"-1"];

//  NSLog(@"====> %@",[dict1 objectForKey:@"users"] );        // Here You get all the data
NSMutableArray *array=[dict1 objectForKey:@"users"];
for(int i=0;i<[array count];i++)
{
    NSLog(@"names:%@",[[array objectAtIndex:i]objectForKey:@"name"]);
}
}

#2


2  

Try this. this code getting the followers and following names

试试这个。此代码获取关注者和以下名称

 ACAccountStore *accountStore = [[ACAccountStore alloc] init];
 ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
 [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
    if (granted) {
        NSArray *accounts = [accountStore accountsWithAccountType:accountType];
        // Check if the users has setup at least one Twitter account
        if (accounts.count > 0)
        {
            ACAccount *twitterAccount = [accounts objectAtIndex:0];

            for(ACAccount *t in accounts)
            {
                if([t.username isEqualToString:username])
                {
                    twitterAccount = t;
                    break;
                }
            }

            SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/friends/ids.json?"] parameters:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@", username], @"screen_name", @"-1", @"cursor", nil]];
            [twitterInfoRequest setAccount:twitterAccount];
            // Making the request
            [twitterInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    // Check if we reached the reate limit
                    if ([urlResponse statusCode] == 429) {
                        NSLog(@"Rate limit reached");
                        return;
                    }
                    // Check if there was an error
                    if (error) {
                        NSLog(@"Error: %@", error.localizedDescription);
                        return;
                    }
                    // Check if there is some response data
                    if (responseData) {
                        NSError *error = nil;
                        NSArray *TWData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];


                    }
                });
            }];
        }
    } else {
        NSLog(@"No access granted");
    }
}];

#1


5  

Use FHSTwitterEngine

#import "FHSTwitterEngine.h"

Add SystemConfiguration.framework

Write following code to your viewDidLoad(for oauth login)

将以下代码写入viewDidLoad(用于oauth登录)

UIButton *logIn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
logIn.frame = CGRectMake(100, 100, 100, 100);
[logIn setTitle:@"Login" forState:UIControlStateNormal];
[logIn addTarget:self action:@selector(showLoginWindow:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:logIn];

[[FHSTwitterEngine sharedEngine]permanentlySetConsumerKey:@"Xg3ACDprWAH8loEPjMzRg" andSecret:@"9LwYDxw1iTc6D9ebHdrYCZrJP4lJhQv5uf4ueiPHvJ0"];
[[FHSTwitterEngine sharedEngine]setDelegate:self];


 - (void)showLoginWindow:(id)sender {
UIViewController *loginController = [[FHSTwitterEngine sharedEngine]loginControllerWithCompletionHandler:^(BOOL success) {
    NSLog(success?@"L0L success":@"O noes!!! Loggen faylur!!!");
    [[FHSTwitterEngine sharedEngine]loadAccessToken];
    NSString *username = [FHSTwitterEngine sharedEngine].authenticatedUsername;
    NSLog(@"user name is :%@",username);
    if (username.length > 0) {
        [self listResults];
    }
}];
     [self presentViewController:loginController animated:YES completion:nil];
}
 - (void)listResults {

NSString *username = [FHSTwitterEngine sharedEngine].authenticatedUsername;
NSMutableDictionary *   dict1 = [[FHSTwitterEngine sharedEngine]listFriendsForUser:username isID:NO withCursor:@"-1"];

//  NSLog(@"====> %@",[dict1 objectForKey:@"users"] );        // Here You get all the data
NSMutableArray *array=[dict1 objectForKey:@"users"];
for(int i=0;i<[array count];i++)
{
    NSLog(@"names:%@",[[array objectAtIndex:i]objectForKey:@"name"]);
}
}

#2


2  

Try this. this code getting the followers and following names

试试这个。此代码获取关注者和以下名称

 ACAccountStore *accountStore = [[ACAccountStore alloc] init];
 ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
 [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
    if (granted) {
        NSArray *accounts = [accountStore accountsWithAccountType:accountType];
        // Check if the users has setup at least one Twitter account
        if (accounts.count > 0)
        {
            ACAccount *twitterAccount = [accounts objectAtIndex:0];

            for(ACAccount *t in accounts)
            {
                if([t.username isEqualToString:username])
                {
                    twitterAccount = t;
                    break;
                }
            }

            SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/friends/ids.json?"] parameters:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@", username], @"screen_name", @"-1", @"cursor", nil]];
            [twitterInfoRequest setAccount:twitterAccount];
            // Making the request
            [twitterInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    // Check if we reached the reate limit
                    if ([urlResponse statusCode] == 429) {
                        NSLog(@"Rate limit reached");
                        return;
                    }
                    // Check if there was an error
                    if (error) {
                        NSLog(@"Error: %@", error.localizedDescription);
                        return;
                    }
                    // Check if there is some response data
                    if (responseData) {
                        NSError *error = nil;
                        NSArray *TWData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];


                    }
                });
            }];
        }
    } else {
        NSLog(@"No access granted");
    }
}];