这是iOS上一个适用于OAuth1的库。
该库灵感来源于FHSTwitterEngine (https://github.com/natesymer/FHSTwitterEngine),但代码更少,更轻量级,且适用于其他所有的OAuth1。
要运行示例项目,首先克隆仓库,然后在Example目录中执行pod install
声明FHSTwitterEngine
[[FHSTwitterEngine sharedEngine] setDelegate:self];
if([[FHSTwitterEngine sharedEngine] isAuthorized]) {
NSLog(@"YES");
[self callUserRequest];
} else {
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"https://api.twitter.com/oauth/access_token", kOAuth1_TOKEN,
@"https://api.twitter.com/oauth/request_token", kOAuth1_REQUEST_TOKEN,
@"https://api.twitter.com/oauth/authorize", kOAuth1_AUTHORIZE,
@"yRtOrW7lOURB0lTSaTWlN2fMv", kOAuth1_CONSUMER_KEY,
@"xOjRhL9mqzFf7Ie6Zv647K8FjPVeQyt2LcyPGAbkPYYae05VwP", kOAuth1_SECRET_KEY, nil];
NSError *err = [[FHSTwitterEngine sharedEngine] authWithInfo:dict];
if (!err) {
UIViewController *loginController = [[FHSTwitterEngine sharedEngine]loginControllerWithCompletionHandler:^(BOOL success) {
if(success) {
NSLog(@"YES");
[self callUserRequest];
} else {
NSLog(@"NO");
}
}];
[self presentViewController:loginController animated:YES completion:^{
}];
}
}
- (void)oauth1Reponsed:(NSDictionary *)dict {
NSLog(@"%@", dict);
}
- (void)callUserRequest {
id data = [[FHSTwitterEngine sharedEngine] sendGETRequestForURL:[NSURL URLWithString:@"https://api.twitter.com/1.1/account/verify_credentials.json"] andParams:nil];
NSLog(@"%@", data);
}
pod "OAuth1"
github "trongdth/OAuth1-for-iOS" "master"
Trong Dinh,[email protected]
OAuth1可以在APACHE许可证下使用。查看LICENSE文件以获取更多信息。