新浪微博iOS示例,登录,获取个人信息
1.导入第三方库和系统框架
2.product设置,注意objc的大小写
3.info.plist设置
4.appDelegate.m
导入头文件
#import "AppDelegate.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKConnector/ShareSDKConnector.h>
#import "WeiboSDK.h"
#import "ViewController.h"
5.在appDelegate.m的didFinishLaunchingWithOptions方法中添加如下代码
// 设置根视图
ViewController *vc = [[ViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
self.window.rootViewController = nav;
//微博授权登陆
[ShareSDK registerApp:@"iosv1101"
activePlatforms:@[@(SSDKPlatformTypeSinaWeibo)]
onImport:^(SSDKPlatformType platformType)
{
switch (platformType)
{
case SSDKPlatformTypeSinaWeibo:
[ShareSDKConnector connectWeibo:[WeiboSDK class]];
break;
default:
break;
}
}
onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
{
switch (platformType)
{
case SSDKPlatformTypeSinaWeibo:
//设置新浪微博应用信息,其中authType设置为使用SSO+Web形式授权
[appInfo SSDKSetupSinaWeiboByAppKey:@"568898243"
appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
redirectUri:@"http://www.sharesdk.cn"
authType:SSDKAuthTypeBoth];
break;
default:
break;
}
}];
6.在viewController.m中添加如下代码
#import "ViewController.h"
#import "WeiboSDK.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKConnector/ShareSDKConnector.h>
@interface ViewController ()
{
UILabel *lab;
UILabel *lab1;
UILabel *lab2;
UILabel *labname;
UILabel *labfan;
UILabel *labfriend;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"新浪微博登陆";
self.view.backgroundColor = [UIColor whiteColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"新浪微博登陆" forState:UIControlStateNormal];
btn.frame = CGRectMake(100, 200, 100, 30);
[self.view addSubview:btn];
[btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn1 setTitle:@"退出" forState:UIControlStateNormal];
btn1.frame = CGRectMake(230, 200, 60, 30);
[self.view addSubview:btn1];
[btn1 addTarget:self action:@selector(click2) forControlEvents:UIControlEventTouchUpInside];
}
-(void)click
{
[ShareSDK getUserInfo:SSDKPlatformTypeSinaWeibo
onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error)
{
if (state == SSDKResponseStateSuccess)
{
NSLog(@"uid=%@",user.uid);
NSLog(@"%@",user.credential);
NSLog(@"token=%@",user.credential.token);
NSLog(@"nickname=%@",user.nickname);
NSLog(@"followerCount=%ld",user.followerCount);
NSLog(@"friendCount=%lu",user.friendCount);
lab = [[UILabel alloc]initWithFrame:CGRectMake(150, 300, 150, 30)];
lab.text = user.nickname;
[self.view addSubview:lab];
lab1 = [[UILabel alloc]initWithFrame:CGRectMake(150, 400, 150, 30)];
lab1.text =[NSString stringWithFormat:@"%ld",user.followerCount];
[self.view addSubview:lab1];
lab2 = [[UILabel alloc]initWithFrame:CGRectMake(150, 500, 150, 30)];
lab2.text =[NSString stringWithFormat:@"%ld",user.friendCount];
[self.view addSubview:lab2];
labname = [[UILabel alloc]initWithFrame:CGRectMake(50, 300, 50, 30)];
labname.text = @"昵称:";
[self.view addSubview:labname];
labfan = [[UILabel alloc]initWithFrame:CGRectMake(50, 400, 100, 30)];
labfan.text = @"粉丝数:";
[self.view addSubview:labfan];
labfriend = [[UILabel alloc]initWithFrame:CGRectMake(50, 500, 100, 30)];
labfriend.text =@"好友数:";
[self.view addSubview:labfriend];
}
else
{
NSLog(@"%@",error);
}
}];
}
-(void)click2
{
[ShareSDK cancelAuthorize:SSDKPlatformTypeSinaWeibo];
[lab removeFromSuperview];
[lab1 removeFromSuperview];
[lab2 removeFromSuperview];
[labfan removeFromSuperview];
[labfriend removeFromSuperview];
[labname removeFromSuperview];
}
@end
效果图:点击授权 显示个人信息 点击退出
新浪微博iOS示例,登录,获取个人信息的更多相关文章
- 最简单的基于DirectShow的示例:获取Filter信息
===================================================== 最简单的基于DirectShow的示例文章列表: 最简单的基于DirectShow的示例:视 ...
- Android之QQ授权登录获取用户信息
有时候我们开发的app须要方便用户简单登录.能够让用户使用自己的qq.微信.微博登录到我们自己开发的app. 今天就在这里总结一下怎样在自己的app中集成QQ授权登录获取用户信息的功能. 首先我们打开 ...
- uni-app开发经验分享二十: 微信小程序 授权登录 获取详细信息 获取手机号
授权页面 因为微信小程序提供的 权限弹窗 只能通用户确认授权 所以可以 写一个授权页面,让用户点击 来获取用户相关信息 然后再配合后台就可以完成登录 <button class="bt ...
- iOS 整理笔记 获取手机信息(UIDevice、NSBundle、NSLocale)
/* iOS的APP的应用开发的过程中,有时为了bug跟踪或者获取用反馈的需要自动收集用户设备.系统信息.应用信息等等,这些信息方便开发者诊断问题,当然这些信息是用户的非隐私信息,是通过开发ap ...
- [转载]iOS开发:获取设备信息
开发iOS平台的应用的时候,可以获取iOS设备的设备信息,包括设备的名称,设备的机型,设备的iOS版本等等.设备信息主要来自 UIDevice 类. UIDevice *currentDevice = ...
- 微信第三方登陆,无需注册一键登录,获取用户信息,PHP实现方法
今天讲讲利用微信oauth2实现第三方登陆的实现方法. 先说说前提吧! 首先你得是服务号,并且是经过认证的.这样微信会给你很多第三方接口的权限,如果是订阅号或者没有认证的服务号那就不用想了! 一开始你 ...
- Python入门小练习 003 利用cookielib模拟登录获取账户信息
为了方便, 使用chinaunix的账户获取账户主题. 有些网站可能需要验证码, 找一些不用验证码的网站 下面 ****** 很多个星号的均为私密信息, 所以用星号代替 #!/usr/bin/pyt ...
- app支付宝授权登录获取用户信息
由后台进行地址的拼接(前台进行授权) // 生成授权的参数 String sign = ""; Long userId1 = SecurityUser.getUserId(); S ...
- Laravel wxxcx 微信小程序获取用户信息
wxxcx 是Laravel5微信小程序登录获取用户信息扩展 部署 12345678 # 安装$ composer require iwanli/wxxcx# 注册服务# 在 /config/app. ...
随机推荐
- Android应用去掉标题栏的方法
1.在代码里实现 this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏,this指当前的Activity 这句代码一定要加在setCon ...
- JS中prototype属性-JS原型模式
/* *对象方法 *类方法 * 原型方法 */ function People(name) { this.name = name; this.say = function () { //对象方法 al ...
- ORA-01152错误解决方法(转)
具体步骤如下: startup force; alter system set "_allow_resetlogs_corruption"=true scope=spfile; r ...
- 返回某个界面——nav
NSInteger index=[[self.navigationController viewControllers]indexOfObject:self]; [self.navigationC ...
- NSNotification消息
注册消息 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(方法) name:@"消息名字&q ...
- python-整理-vs2013新建文件编码
使用VS2013新建py包和py空文件还有文本文件时发现编码是936.如果代码中写了中文关闭后再打开就乱码了. 找了几个小时,发现模板文件就是936编码,奇怪的是pyclass等其它模板是正常的UTF ...
- [转]Cocos2d-x建工程时避免copy文件夹和库
原文链接: http://www.cnblogs.com/andyque/archive/2011/09/27/2192920.html 在上一篇教程中,我们演示了如何使用VS2010来新建一个工程 ...
- css3 页面退出和进入的动画
@-webkit-keyframes slideIn { from { -webkit-transform: translate3d(100%,0,0); transform: translate3d ...
- mysql的client和sever之间通信password的传输方式
本文想要说明的是,当我们用mysql -uroot -p1234567 -h127.0.0.1 -P3306 去连接mysql server时密码是通过什么样的形式传过去的呢? 首先密码这种东西明文传 ...
- Windows中安装Emacs
首先从http://gnu.org/software/emacs中下载window下的压缩包,然后解压..运行ROOT/bin/addpm.exe进行安装. 将鼠标右键添加Emacs编辑: 1. 打开 ...