OAuth1 0.3

OAuth1 0.3

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2017年5月

Trong Dinh维护。



OAuth1 0.3

OAuth1-for-iOS

这是iOS上一个适用于OAuth1的库。

概览

该库灵感来源于FHSTwitterEngine (https://github.com/natesymer/FHSTwitterEngine),但代码更少,更轻量级,且适用于其他所有的OAuth1。

使用方法

  1. 要运行示例项目,首先克隆仓库,然后在Example目录中执行pod install

  2. 声明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:^{
                
            }];
        }

    }
  1. 实现FHSTwitterEngineAccessTokenDelegate方法以获取accesstoken
- (void)oauth1Reponsed:(NSDictionary *)dict {
    NSLog(@"%@", dict);
}
  1. 调用自定义请求
- (void)callUserRequest {
    id data = [[FHSTwitterEngine sharedEngine] sendGETRequestForURL:[NSURL URLWithString:@"https://api.twitter.com/1.1/account/verify_credentials.json"] andParams:nil];
    NSLog(@"%@", data);
}

安装

  1. Pod
  • OAuth1可以通过CocoaPods访问。要安装它,只需将以下行添加到Podfile中
pod "OAuth1"
  1. Carthage
  • 对于Carthage安装
github "trongdth/OAuth1-for-iOS" "master"

作者

Trong Dinh,[email protected]

许可证

OAuth1可以在APACHE许可证下使用。查看LICENSE文件以获取更多信息。