使用Xcode中的Objective-C进行编码并使用twitter API(ACAccountStore& SLRequest);
我正试图在twitter中获取我的关注者列表我把它放在'postRequest'的嵌套块中,第二个帖子请求总是导致“错误的身份验证数据”。任何人都可以帮我解决这个问题吗?
- (void) getFollowerList:(void (^)(NSDictionary *, NSError *))block withAccountName:(NSString *) accountName
{
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType
options:nil
completion:^(BOOL granted, NSError *error)
{
if(granted == YES)
{
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
ACAccount *twitterAccount = [arrayOfAccounts lastObject];
NSURL *requestURL = [NSURL URLWithString:@"https://api.twitter.com/1.1/friends/ids.json"];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:accountName forKey:@"screen_name"];
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodGET
URL:requestURL
parameters:parameters];
postRequest.account = twitterAccount;
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse
*urlResponse, NSError *error)
{
if (responseData) {
if (error) {
NSLog(@"%@",error);
block(nil,error);
}
else{
NSDictionary *temp = [NSJSONSerialization JSONObjectWithData:responseData
options:NSJSONReadingMutableContainers
error:&error];
NSLog(@"%@",temp);
NSArray *accountArray = temp[@"ids"];
NSLog(@"%@",accountArray);
NSURL *requestURL = [NSURL URLWithString:@"https://api.twitter.com/1.1/users/lookup.json"];
NSMutableDictionary *parameters =[[NSMutableDictionary alloc] init];
[parameters setObject:accountArray forKey:@"screen_name"];
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodGET
URL:requestURL
parameters:parameters];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if (responseData)
{
if (error) {
NSLog(@"%@",error);
block(nil,error);
}
else{
NSDictionary *temp = [NSJSONSerialization JSONObjectWithData:responseData
options:NSJSONReadingMutableContainers
error:&error];
NSLog(@"%@",temp);
}
}
}];
}
}
}];
}
}else {
NSLog(@"account access not granted");
}
}];
}
*即使我试图将请求加倍,所以“朋友/ ids”首先是“朋友/ ids”。第二个朋友/ ids仍然导致错误的身份验证数据。