Larry Borsato

1pod

OAuthConsumer

OAuthConsumer

这是 Jon Crosby 创建的 http://oauth.googlecode.com/svn/code/obj-c/OAuthConsumer 的 iPhone 准备版。

这个版本已经更新以兼容 iOS 8.0 和使用自动引用计数(ARC)。您需要添加 Security.framework

"iPhone ready" 仅意味着您只需将文件添加到 Xcode 中,并导入 "OAuthConsumer.h"。

OADataFetcher 现在除了可以像在这个示例中看到的那样使用代理外,还可以使用代码块。

OAConsumer *consumer = [[OAConsumer alloc] initWithKey:self.consumerKey secret:self.consumerSecret];
OAToken *token = [[OAToken alloc] initWithKey:self.accessToken secret:self.accessTokenSecret];
NSURL* url = [NSURL URLWithString:urlString];
OAMutableURLRequest* request = [[OAMutableURLRequest alloc] initWithURL:url consumer:consumer token:token realm:nil signatureProvider:nil];
[request setHTTPMethod:@"POST"];
NSMutableArray *params = [[NSMutableArray alloc] init];
for ( NSString *key in [postParams allKeys] )
{
    OARequestParameter* param = [[OARequestParameter alloc] initWithName:key value:postParams[key]];
    [params addObject:param];
}
if ( [params count] > 0 )
    [request setParameters:params];
OADataFetcher* dataFetcher = [[OADataFetcher alloc] init];
[dataFetcher performRequest:request
                withHandler:^(OAServiceTicket *ticket, NSData *data, NSError *error) {
               if ( !error ) {
                   NSLog(@"didPost:=%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
                   [self updateStatusCompleteWithStatus:SCUpdateSuccessful data:data error:nil];
               }
               else
               {
                   [self updateStatusCompleteWithStatus:SCUpdateFailed data:data error:error];
               }
           }];

这是一个正在进行中的项目。请随时通过 larry [at] larryborsato [dot] com 联系我。

许可证: MIT

  • Objective C