新浪微博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. ...
随机推荐
- c3p0连接数据库
<?xml version="1.0" encoding="UTF-8"?> <c3p0-config> <default-con ...
- ios 调用相机后 view 下沉问题
我只加了一句代码 现在不报错了 因为这个问题是随机性的 我也不太明白这个地方是怎么回事 我只是这样子做了 问题不出来了 if ([[[UIDevice currentDevice] syst ...
- ExtJS 饼状图报表
简单的ExtJS饼状图报表. 先上源码,咱再慢慢解析: Ext.onReady(function(){ var store = Ext.create('Ext.data.JsonStore', { f ...
- (译+原)std::shared_ptr及std::unique_ptr使用数组
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5462363.html 参考网址: http://stackoverflow.com/questions ...
- ORACLE11G常用函数
1 单值函数 1.1 日期函数 1.1.1 Round [舍入到最接近的日期](day:舍入到最接近的星期日) select sysdate S1, round(sysdate) S2 , round ...
- jira汉化
https://translations.atlassian.com/dashboard/dashboard 下载汉化jar文件,在jira中上传插件,系统设置中文即可 LOFTER:我们的故事 ...
- php get_ini 和 get_cfg_var 的区别
get_ini 和 get_cfg_var 都是用来获取 php 配置信息的函数. 区别是 get_ini 是用来获取当前运行的配置信息,get_cfg_var 是用来获取配置文件(php.ini)的 ...
- C和指针c6-1
#include<stdio.h> #include<stdlib.h> char *find_char(char const *source_str, char const ...
- 【Shell脚本】运行shell脚本文件的几种方法与区别
Shell脚本不同的运行方式会对当前Shell设置或者运行结果有所不同. 假设现在有一个脚本名为display_shell_script_args.sh,其内容如下: #!/home/pyf/bin/ ...
- LeeCode-Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 /** * Definition for a ...