ImgurSession 1.3

ImgurSession 1.3

测试已测试
语言编程语言 Objective-CObjective C
许可证 MIT
发布最新版本2016年3月

Geoff Macdonald 负责。



  • Geoff MacDonald

ImgurSession 是一个 Objective-C 网络库,易于在 iOS 和 OS X 应用程序中发送 Imgur API 请求。它基于 AFNetworking 的 AFHTTPSessionManager 基础类。ImgurSession 提供了 API V3 的访问权限。它处理用户认证会话的 OAuth2 认证,也支持匿名会话的基本认证。它涵盖了 Imgur 文档中所有的端点。这正在我的免费应用程序 Imgurian 的生产中使用。

该项目最初由 Johann Pardanaud 从 ImgurKit 分叉而来,并进行了重构。

特性

  • 完整的 Imgur API V3

    • 使用 ImgurSession/Request 文件夹中的任何请求类进行请求。请求使用在请求之前创建的会话单例。
    • 图像、专辑、评论、通知、消息、对话和账户的 CRUD 操作。
    • 多图像上传,从 URL 上传。
  • OAuth2 管理。

    • 会话只需要您的应用程序凭据。处理所有认证(除了需要 webview 的情况)。
    • 会话将懒惰地刷新您的令牌。您可以随时使用任何请求。
  • 用户账户

    • 会话每 1 分钟自动通知代理响应用户账户的回复和消息。可以禁用。
    • 会话在每小时令牌过期时刷新用户的账户。

使用 ImgurSession

只需导入 ImgurSession.h 并使用您的凭据设置会话,然后进行任何请求。对于用户授权,您必须根据令牌类型向 OAuth 2 授权注册,带有或没有回调 URL(在 Imgur 上阅读更多)。对于授权登录,您必须实现 imgurSessionNeedsExternalWebview: 代理方法,以便打开一个外部的 imgur.com 页面进行 OAuth 授权。


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
     [IMGSession authenticatedSessionWithClientID:@"clientID" secret:@"secret" authType:IMGCodeAuth withDelegate:self];

    return YES;
}

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{

    /*
    configure you app URL schema to handle the callback url then call completion with retrieved code from URL
    */

}

#pragma mark - IMGSessionDelegate

-(void)imgurSessionNeedsExternalWebview:(NSURL *)url completion:(void (^)())completion{

    //open imgur website to authenticate with callback url in safari
    [[UIApplication sharedApplication] openURL:url];

    //save the completion block for later use when imgur responds with url callback
}

或者匿名会话(如注册的 Imgur 应用程序所配置的)。

[IMGSession anonymousSessionWithClientID:@"anonToken" withDelegate:self];

在其他任何应用程序位置,都会使用先前创建的会话单例进行请求以处理认证和错误处理。要检索病毒画廊:

    [IMGGalleryRequest hotGalleryPage:0 success:^(NSArray *objects) {

        //use gallery objects in a table for example
        self.tableRows = objects;
        [self.tableView reloadData];

    } failure:^(NSError *error) {

        //handle error
    }];