关闭

友盟SDK应用(一)------第三方登陆

标签: IOS开发友盟开放平台
407人阅读 评论(0) 收藏 举报
分类:

初期准备:

1、到友盟官网下载SDK http://dev.umeng.com/

2、到需要使用的第三方登陆方开放平台注册

微信开放平台:http://open.weixin.qq.com/    (AppID、AppSecret)

腾讯开放平台:http://open.qq.com/               (AppID、AppKey)

微博开放平台:http://open.weibo.com/         (AppKey、App_Secret)


使用:

一、添加友盟SDK到项目中

二、配置URL schemes
  新浪微博     “sina.”+友盟appkey,例如“sina.507fcab25270157b37000010”
  微信     微信应用appId,例如“wxd9a39c7122aa6516”,微信详细集成步骤参考微信集成方法
  人人网     “rm”+你的应用bundle id,例如“rmcom.umeng.SocialSDK”
  QQ、QQ空间     需要添加两个URL schemes

    1. “QQ”+腾讯QQ互联应用appId转换成十六进制(不足8位前面补0),例如“QQ05FC5B14”。生成十六进制方法:点击链接。“tencent“+腾讯QQ互联应用Id,例如

    2.“tencent100424468" ,QQ及Qzone详细集成步骤参考手机QQ集成方法

三、在appDelegate 中添加代码

1、导入头文件

  #import "UMSocial.h"
  #import "UMSocialWechatHandler.h"
  #import "UMSocialQQHandler.h"
  #import "UMSocialSinaHandler.h"

2、注册相关第三方ID || KEY

   

    [UMSocialWechatHandler setWXAppId:UM_WECHAT_AppID appSecret:UM_WECHAT_AppSecret url:@"http://www.umeng.com/social"];
    [UMSocialQQHandler setQQWithAppId:UM_QQ_APPID appKey:UM_QQ_APPKEY url:@"http://www.umeng.com/social"];
    [UMSocialSinaHandler openSSOWithRedirectURL:UM_AUTH_CALLBACK];

四、在登陆出调用

1、微博

    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];

    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
        //          获取微博用户名、uid、token等
        NSLog(@"code=%@",response.data);
        
        if (response.responseCode == UMSResponseCodeSuccess) {
            
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
            NSLog(@"微博登陆 username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
            
            }];            
        }});
2、QQ

    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){

        NSLog(@"code=%@",response.data);
    
        if (response.responseCode == UMSResponseCodeSuccess) {
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToQQ];
            
            DLog(@"username is %@, uid is %@, token is %@ 头像url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);

        }
    });
3、微信

    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
        NSLog(@"code=%@",response.data);
        
        if (response.responseCode == UMSResponseCodeSuccess) {
            
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary]valueForKey:UMShareToWechatSession];
            
            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);

        }
        
    });

PS:至此已完成地方登陆所需获取的UID、token、name、image

注:

1、token具有有效期 有效期过重新获取会变更,注册最好用使用固定的uid

2、微博跳转第三方登陆 需要使用SSO登陆 下载SDK时要勾选,否则只会跳转网页登陆授权

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1510次
    • 积分:54
    • 等级:
    • 排名:千里之外
    • 原创:4篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档