【发布时间】:2015-07-14 10:12:09
【问题描述】:
我正在尝试访问 Twitter API 的单个部分,而无需登录用户帐户(我想要的是仅应用程序身份验证),所以我不想添加一些框架来执行这一操作.我正在尝试使用 AFNetworking 来代替这里的描述:https://dev.twitter.com/oauth/reference/post/oauth2/token。
这是我目前所拥有的
AFOAuth2Manager *authManager = [[AFOAuth2Manager alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.twitter.com/"]
clientID:TwitterAPIKey
secret:TwitterSecret];
[authManager authenticateUsingOAuthWithURLString:@"oauth2/token"
parameters:nil
success:^(AFOAuthCredential *credential) {
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:TwitterBaseURL]];
[manager.requestSerializer setAuthorizationHeaderFieldWithCredential:credential];
//do some stuff
}
failure:^(NSError *error) {
//handle the failure, where I'm currently ending up
}];
运行时,它无法通过 403 禁止错误进行身份验证。谁能向我解释我哪里出错了?
【问题讨论】:
标签: ios objective-c afnetworking twitter-oauth twitter-rest-api