1

我正在开发一个基于 Twitter 的应用程序,我想在其中获取已登录 Twitter 用户的朋友列表。我为此做了一个代码,但它返回错误。

NSMutableArray *arr = [[NSMutableArray alloc] init];


    NSMutableDictionary *accountDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:account.username, @"screen_name", nil];

    [accountDictionary setObject:[[[account dictionaryWithValuesForKeys:[NSArray arrayWithObject:@"properties"]] objectForKey:@"properties"] objectForKey:@"user_id"] forKey:@"user_id"];

    NSURL *followingURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.twitter.com/1.1/friends/list.json?cursor=-1&screen_name=%@&skip_status=true&include_user_entities=false",account.username]];

    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:account.username, @"screen_name", nil];

    TWRequest *twitterRequest = [[TWRequest alloc] initWithURL:followingURL
                                                    parameters:parameters
                                                 requestMethod:TWRequestMethodGET];

    [twitterRequest setAccount:account];



        NSError *jsonError = nil;
    NSData *responseData;

        NSDictionary *twitterFriends = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONWritingPrettyPrinted error:&jsonError];

        [accountDictionary setObject:[twitterFriends objectForKey:@"list"] forKey:@"friends_list"];

    return arr;

我收到此错误:

{ errors = ( { code = 34; message = "抱歉,该页面不存在"; } ); }

4

1 回答 1

1
  ACAccountStore *accountStore = [[ACAccountStore alloc] init];
  ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
  [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
    if (granted==YES) {
        NSArray *accounts = [accountStore accountsWithAccountType:accountType];
        if (accounts.count) {
            ACAccount *twitterAccount = [accounts objectAtIndex:0];
            NSString *str =twitterAccount.accountDescription;
            NSString *newStr = [str substringFromIndex:1];

            id request=nil;
            NSString *profileurl=@"http://api.twitter.com/1/friends/ids.json?&screen_name=";
            NSString *url1= [NSString stringWithFormat:@"%@%@",profileurl,newStr];
            NSURL *url = [NSURL URLWithString:url1];

            TWRequest *request = [[TWRequest alloc] initWithURL:url  parameters:nil 
                   requestMethod:TWRequestMethodGET];

            [request setAccount:twitterAccount];
           [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    NSError *error = nil;
                    NSDictionary *profileimageurl =[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error] ;
                    //here you get dictionary of your friends ids


                 });
            }];
于 2012-12-06T11:07:34.323 回答