当前位置:首页 > 开发教程 > 手机开发 >

Instagram_OAuth2.0_iOS登录认证 Framework

时间:2014-04-30 09:12 来源: 作者: 收藏

Instagram OAuth2.0 登录认证 Framework

最近在做各个应用的第三方授权登录,Facebook 、instagram、google+、twitter、QQ、Sina等。

大部分都有现成的framework, 当然instagram也有documentation讲解。

但是和其他应用不同的是,其他应用授权成功后一般都有一个userid/openid/uid  和accesstoken 作为登录自己应用的参数,但是 按照instagram 的 documentation中client端的授权方式,只能拿到一个accesstoken--直接导致后面的获取用户信息的API无法使用。所以自己封装了一个framework,获取授权信息和用户信息。

传送门(资源审核巨慢!!!有空再加链接吧)

(Twitter正在研究中,iOS自身已经支持从setting中读取twitter信息,但是读取的信息也不够多,所以正在尝试web授权方式)

framework运行环境:iOS7.0+  、arc

接口类:

 

//
//  InstagramAuthorizeManager.h
//  ILSLoginManager
//
//  Created by hupeng on 14-4-29.
//  Copyright (c) 2014年 toprankapps. All rights reserved.
//


#import <Foundation/Foundation.h>
#import "InstagramMacro.h"

@interface InstagramAuthorizeManager : NSObject

+ (InstagramAuthorizeManager *)sharedManager;

+ (void)authorizeWithClientID:(NSString *)clientID
                clientSecrect:(NSString *)clientSecrect
                  redirectURI:(NSString *)redirectURI
         parentViewController:(UIViewController *)viewController
            completionHandler:(InstagramAuthorizeCompletionHandler)completionHandler;

@end

可获取的信息如下:

 

 

//
//  InstagramModel.h
//  ILSLoginManager
//
//  Created by hupeng on 14-4-29.
//  Copyright (c) 2014年 toprankapps. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface InstagramModel : NSObject

// 在返回信息中将被清空
@property (nonatomic, strong) NSString *clientID;
@property (nonatomic, strong) NSString *clientSecrect;
@property (nonatomic, strong) NSString *redirectURI;
@property (nonatomic, strong) NSString *code;
// 返回信息
@property (nonatomic, strong) NSString *accessToken;
@property (nonatomic, strong) NSString *username;
@property (nonatomic, strong) NSString *bio;
@property (nonatomic, strong) NSString *website;
@property (nonatomic, strong) NSString *image;
@property (nonatomic, strong) NSString *fullName;
@property (nonatomic, strong) NSString *uid;

@end

 

 

Example(下面是我自己管理第三方授权的Manager中的使用情况):

 

- (void)openInstagramAuthorizePage
{
    // 1.login using cached data
    if ([ILSCPSocialManager instagramHasLogin]) {
        [self loginWithInstagramAccount];
        return;
    }
    ILSCPSocialManager *manager = [ILSCPSocialManager sharedManager];
    
    [InstagramAuthorizeManager authorizeWithClientID:manager.instagramClientID
                                       clientSecrect:manager.instagramClientSecrect
                                         redirectURI:manager.instagramRedirectURL
                                parentViewController:_parentViewController
                                   completionHandler:^(NSError *error, InstagramModel *instagramInstance) {
        
        if (error) {
            _completionHandler(error);
            return;
        }
        // init userprofile
        _profile.userName = instagramInstance.uid;
        _profile.sex = nil;
        _profile.firstName = nil;
        _profile.lastName = nil;
        _profile.email = nil;
                                       
        // 3.save login informations
        [ILSCPSocialManager sharedManager].instagramAccessToken = instagramInstance.accessToken;
        [ILSCPSocialManager sharedManager].instagramUID = instagramInstance.uid;
        // 4.login
        _requestStartHandler();
        
        [self loginWithInstagramAccount];
    }];
}


 

 


 

更多

手机开发阅读排行

最新文章