2012-12-06 35 views
1

我正在基於Twitter的應用程序中,我想要獲取登錄的Twitter用戶的朋友列表。我已經爲此做了一個代碼,但它返回錯誤。如何在iPhone中獲取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 = "Sorry, that page does not exist"; }); }

+0

可能是你應該在這裏張貼此錯誤??? – Stas

+0

它給這個錯誤它不顯示朋友列表{ 誤差=( { 代碼= 34; 消息=「抱歉,該頁面不存在」; } ); } – Rani

+0

你確定'followingUrl'以正確的方式組成嗎? – Stas

回答

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 *[email protected]"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 


       }); 
      }]; 
+0

喜玫瑰我已經寫我們的代碼,但它在這條線socialRequestClass requestForServiceType給出了錯誤:SLServiceTypeTwitter requestMethod:SLRequestMethodGET 網址:網址 參數:無 – Rani

+0

使用未聲明的標識符SLServiceTypeTwitter – Rani

+0

添加Social.framework和進口#進口<社會/ SLRequest .H> – Rose

相關問題