AF2OAuth1Client 0.3.6

AF2OAuth1Client 0.3.6

测试测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2015年3月

Andrey Yastrebov 维护。



AFOAuth1Client

说明

将应用程序注册为可以通过 自定义 URL 方案启动,并使用路径 success 作为您的回调 URL。自定义 URL 方案的回调应该发送通知,这将完成 OAuth 交易。

以下是创建客户端和进行身份验证的方法

AFOAuth1Client *twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.twitter.com/1.1/"] key:@"..." secret:@"..."];

// Your application will be sent to the background until the user authenticates, and then the app will be brought back using the callback URL
[self.twitterClient authorizeUsingOAuthWithRequestTokenPath:@"/oauth/request_token" userAuthorizationPath:@"/oauth/authorize" callbackURL:[NSURL URLWithString:@"af-twitter://success"] accessTokenPath:@"/oauth/access_token" accessMethod:@"POST" scope:nil success:^(AFOAuth1Token *accessToken, id responseObject) {
    NSMutableURLRequest *request = [self.twitterClient requestWithMethod:@"GET" path:@"statuses/user_timeline.json" parameters:nil];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperationManager manager] HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Success: %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", [error localizedDescription]);
    }];
    [manager.operationQueue addOperation:operation];
} failure:^(NSError *error) {
    NSLog(@"Error: %@", error);
}];

以下是 iOS 上如何响应自定义 URL 方案

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    NSNotification *notification = [NSNotification notificationWithName:kAFApplicationLaunchedWithURLNotification object:nil userInfo:[NSDictionary dictionaryWithObject:url forKey:kAFApplicationLaunchOptionsURLKey]];
    [[NSNotificationCenter defaultCenter] postNotification:notification];

    return YES;
}

联系人

Joel Chen

http://lnkd.in/bwwnBWR

许可证

AFOAuth1Client 基于 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。