如何在iPhone中获取twitter用户的好友列表?
我正在开发一个基于Twitter的应用程序,我想获取登录Twitter用户的好友列表。我已经为此编写了一个代码,但它返回了错误如何在iPhone中获取twitter用户的好友列表?,iphone,objective-c,Iphone,Objective C,我正在开发一个基于Twitter的应用程序,我想获取登录Twitter用户的好友列表。我已经为此编写了一个代码,但它返回了错误 NSMutableArray *arr = [[NSMutableArray alloc] init]; NSMutableDictionary *accountDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:account.username, @"screen_name", ni
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=“对不起,该页不存在”;});}
可能你应该在这里发布这个错误???它给出了这个错误,它不显示朋友列表{errors=({code=34;message=“对不起,那个页面不存在”;})您确定
followingUrl
的组成方式正确吗?可能您应该在此处发布此错误???它给出此错误,但不显示好友列表{errors=({code=34;message=“对不起,该页面不存在”;})你确定followingUrl
的组成方式正确吗?嗨,罗斯,我已经编写了你的代码,但它在这一行给出了错误socialRequestClass RequestForService类型:SLServiceTypeTwitter requestMethod:SLRequestMethodGETURL:URL参数:无未声明标识符的使用SLServiceTypeTwitter只需将SLRequest请求更改为TWRequest类,在该请求中=[socialRequestClass RequestForService类型:SLServiceTypeTwitter请求方法:SLRequestMethodGET URL:URL参数:nil];大家好,Rose,我已经编写了代码,但在这一行socialRequestClass RequestForService类型:SLServiceTypeTwitter请求方法:SLRequestMethodGET URL:URL出现错误参数:不使用未声明的标识符SLServiceTypeTwitter只需将SLRequest请求更改为TWRequest类,此请求中=[socialRequestClass RequestForService类型:SLServiceTypeTwitter请求方法:SLRequestMethodGET URL:URL参数:nil];让我们
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
});
}];