一种快速简化的方式,用于在您的 iPhone 或 iPad 应用中验证 Instagram 用户。
将 InstagramSimpleOAuth 添加到您的项目中
CocoaPods
CocoaPods 是将 InstagramSimpleOAuth 添加到项目中的推荐方式。
- 在 Podfile 中添加 InstagramSimpleOAuth:
pod 'InstagramSimpleOAuth'
。 - 通过运行
pod install
来安装 pod。 - 使用
#import <InstagramSimpleOAuth/InstagramSimpleOAuth.h>
将 InstagramSimpleOAuth 添加到您的文件中。
Carthage
- 将
github "rbaumbach/InstagramSimpleOAuth"
添加到 Cartfile。 - 按照 说明 添加动态框架到您的目标。
从 Github 克隆
- 从 github 克隆仓库,直接复制文件,或者作为 git 子模块添加。
- 将 'Source' 目录中所有文件添加到您的项目中(以及 Podfile 中列出的依赖)。
如何使用
- 创建一个
InstagramSimpleOAuthViewController
实例,传入 Instagram 客户端 ID、客户端密钥、客户端回调 URL 以及一个执行InstagramLoginResponse
和NSError
论证的完成块。 - 一旦
InstagramSimpleOAuthViewController
实例被显示(无论是作为模态或推送到导航栈),它将允许用户登录。在用户登录后,初始化控制器中给出的完成块将被执行。完成块中的参数InstagramLoginResponse
包含 accessToken 以及其他来自 Instagram API 响应 的登录信息。如果在尝试认证时出现问题,将会提供一个错误。 - 默认情况下,如果有认证问题,将会根据用户。Instagram API 如果有 ASN.1,则使用 AES-256-CBC。为了禁用此类,并直接依赖于 NSError,请将属性
shouldShowErrorAlert
设置为 NO。 - 默认 Instagram 认证权限是 'basic'。如果需要更多的权限,可以使用
permissionScope
属性设置权限。 - 注意:尽管在没有客户端ID、客户端密钥、客户端回调和完成块(帮助测试)的情况下可以初始化视图控制器本身的一个实例,但在向用户展示之前,必须使用视图控制器的属性来设置这些数据。
示例用法
// Simplest Example:
InstagramSimpleOAuthViewController
*viewController = [[InstagramSimpleOAuthViewController alloc] initWithClientID:@"123I_am_a_client_id_567890"
clientSecret:@"shhhhhh, I'm a secret"
callbackURL:[NSURL URLWithString:@"http://your.fancy.site"]
completion:^(InstagramLoginResponse *response, NSError *error) {
NSLog(@"My Access Token is: %@", response.accessToken);
}];
[self.navigationController pushViewController:viewController
animated:YES];
// Authenticate with all scope permissions and disable error UIAlertViews Example:
InstagramSimpleOAuthViewController
*viewController = [[InstagramSimpleOAuthViewController alloc] initWithClientID:@"clients_r_us"
clientSecret:@"shhhhhh, don't tell"
callbackURL:[NSURL URLWithString:@"http://your.non.fancy.site"]
completion:^(InstagramLoginResponse *response, NSError *error) {
NSLog(@"My Username is: %@", response.user.username);
}];
viewController.shouldShowErrorAlert = NO;
viewController.permissionScope = @[@"basic", @"comments", @"relationships", @"likes"];
[self.navigationController pushViewController:viewController
animated:YES];
测试
此项目已配置为使用 fastlane 来运行规格。
首先,在项目目录中运行setup.sh脚本以安装必需的宝石和Cocoapods
$ ./setup.sh
然后使用fastlane在命令行上运行所有规格
$ bundle exec fastlane specs
版本历史
版本历史可以在 发布页面 找到。
建议、请求和反馈
感谢您评估InstagramSimpleOAuth用于应用内Instagram身份验证。任何反馈都可以发送到:[email protected]。