第三方登录(微博)
来源:互联网 发布:端口嗅探 编辑:程序博客网 时间:2024/05/22 10:35
经过项目的测试,上线,现在第三方登录已经彻底通顺,并且对最近发布的IOS10做了适配(这里只对微博做分析)。
网上对新浪微博的第三方登录案例非常之多,相信这部分大多数同学都能够解决,利用第三方登录无非是导入第三方库,然后使用[WeiboSDK handleOpenURL:url delegate:self];即可完成登录功能。
但是既然使用第三方,我们更多的是使用第三方的信息,这里我们以获取第三方(微博)用户信息为例解释下,接下来的步骤。
- (void)didReceiveWeiboResponse:(WBBaseResponse *)response{ if ([response isKindOfClass:WBAuthorizeResponse.class]) { if ((int)response.statusCode == 0) { [SVProgressHUD showWithStatus:NSLocalizedString(@"小阅正在登录中...", nil)]; NSDictionary *resultDic =response.userInfo; //获取用户的微博头像需要的参数 NSString *weiboToken =resultDic[@"access_token"]; NSString *weiboUid = resultDic[@"uid"]; //请求网络获取用户微博的信息 NSString *urlString =[NSString stringWithFormat:@"https://api.weibo.com/2/users/show.json?access_token=%@&uid=%@",weiboToken,weiboUid]; AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; [manager GET:urlString parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) { } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil]; [QFStoreUserDefaults setFromThirdPlat:@"weibo"]; NSString *weibonickStr = resultDic[@"screen_name"]; NSString *weiboIdStr = resultDic[@"id"]; NSString *weiboPhotoStr = resultDic[@"profile_image_url"]; return; } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"获取用户微博信息失败", nil)]; }]; } }}
上面就是利用回调获取到用户的uid和accesstoken去请求另一个接口,即用户信息接口。这样才算获取到用户的信息,也真正达到了使用第三方的作用,看到网上也有很多同学其实也是被阻拦到了这里。
最后上一下这个接口返回的数据以及其他所有的接口地址微博其它信息接口
返回结果JSON示例{ "id": 1404376560, "screen_name": "zaku", "name": "zaku", "province": "11", "city": "5", "location": "北京 朝阳区", "description": "人生五十年,乃如梦如幻;有生斯有死,壮士复何憾。", "url": "http://blog.sina.com.cn/zaku", "profile_image_url": "http://tp1.sinaimg.cn/1404376560/50/0/1", "domain": "zaku", "gender": "m", "followers_count": 1204, "friends_count": 447, "statuses_count": 2908, "favourites_count": 0, "created_at": "Fri Aug 28 00:00:00 +0800 2009", "following": false, "allow_all_act_msg": false, "geo_enabled": true, "verified": false, "status": { "created_at": "Tue May 24 18:04:53 +0800 2011", "id": 11142488790, "text": "我的相机到了。", "source": "<a href="http://weibo.com" rel="nofollow">新浪微博</a>", "favorited": false, "truncated": false, "in_reply_to_status_id": "", "in_reply_to_user_id": "", "in_reply_to_screen_name": "", "geo": null, "mid": "5610221544300749636", "annotations": [], "reposts_count": 5, "comments_count": 8 }, "allow_all_comment": true, "avatar_large": "http://tp1.sinaimg.cn/1404376560/180/0/1", "verified_reason": "", "follow_me": false, "online_status": 0, "bi_followers_count": 215}关于错误返回值与错误代码,参见 错误代码说明返回字段说明返回值字段 字段类型 字段说明id int64 用户UIDidstr string 字符串型的用户UIDscreen_name string 用户昵称name string 友好显示名称province int 用户所在省级IDcity int 用户所在城市IDlocation string 用户所在地description string 用户个人描述url string 用户博客地址profile_image_url string 用户头像地址(中图),50×50像素profile_url string 用户的微博统一URL地址domain string 用户的个性化域名weihao string 用户的微号gender string 性别,m:男、f:女、n:未知followers_count int 粉丝数friends_count int 关注数statuses_count int 微博数favourites_count int 收藏数created_at string 用户创建(注册)时间following boolean 暂未支持allow_all_act_msg boolean 是否允许所有人给我发私信,true:是,false:否geo_enabled boolean 是否允许标识用户的地理位置,true:是,false:否verified boolean 是否是微博认证用户,即加V用户,true:是,false:否verified_type int 暂未支持remark string 用户备注信息,只有在查询用户关系时才返回此字段status object 用户的最近一条微博信息字段 详细allow_all_comment boolean 是否允许所有人对我的微博进行评论,true:是,false:否avatar_large string 用户头像地址(大图),180×180像素avatar_hd string 用户头像地址(高清),高清头像原图verified_reason string 认证原因follow_me boolean 该用户是否关注当前登录用户,true:是,false:否online_status int 用户的在线状态,0:不在线、1:在线bi_followers_count int 用户的互粉数lang string 用户当前的语言版本,zh-cn:简体中文,zh-tw:繁体中文,en:英语
0 0
- 第三方登录(微博)
- 第三方登录(微博)
- 微博 第三方登录
- 第三方登录(一)
- 第三方登录(二)
- 第三方登录(ShareSDK)
- 第三方登录+分享();
- 第三方登录(百度账号登录)
- 第三方登录(QQ登录)
- java第三方登录(微博,QQ)详细代码
- 微博,微信第三方登录UM
- 【第三方登录】第三方登录 Part1 —— QQ登录(2016-09最新版)
- android QQ第三方登录(一)
- Android QQ第三方登录(二)
- 第三方登录(Facebook) java验证
- 第三方登录(传递QQ头像)
- 第三方登录(QQ登陆)实现
- 网站第三方登录(php版)
- VS2010每次调试都出现“此项目已经过期”提示
- 笔记 :malloc的使用
- poj 3252 Round Numbers(二进制数位DP)
- 自己驱动自己—Python代码写接口测试(一)
- JDK源码分析(1)-java.util.ArrayList
- 第三方登录(微博)
- 深入剖析Guice(Google依赖注入框架)
- 数据结构实验之二叉树七:叶子问题
- Atitit prj 项目管理与行政管理(1)------项目环境的概览与建立
- Ionic2显示数据
- 快速排序
- 如何注册Tomcat到Window Service服务
- C#语言与面向对象技术(3)
- 深度好文丨读完此文,就知道Hadoop了!