我正在尝试使用以下代码访问用户的 Twitter 凭据:
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil
completion:^(BOOL granted, NSError *error)
{
if (granted)
{
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
ACAccount *twitterAccount = [arrayOfAccounts lastObject];
NSURL *requestURL = [NSURL URLWithString:@"https:api.twitter.com/1.1/account/verify_credentials.json"];
SLRequest *getRequest = [SLRequest
requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodGET
URL:requestURL parameters:nil];
[getRequest setAccount:twitterAccount];
[getRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];
NSLog(@"Twitter Response : %@ ",json);
}];
}
};
}];
}
使用此代码,我收到此错误:
Twitter Response : {
errors = (
{
code = 32;
message = "Could not authenticate you";
}
);
}
奇怪的是,如果我尝试发推文或访问 Twitter 的某个其他端点,其中需要有一个 oauth-token,则操作成功结束。