我在 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");
}
}];
}
*即使我试图加倍请求所以首先是“朋友/ID”然后是“朋友/ID”。第二个朋友/身份仍然导致错误的身份验证数据。