新浪微博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. ...
随机推荐
- access数据库的连接字符串以及数据库操作类
<!--access数据库连接方式--> <add name="QYTangConnectionString" connectionString="Pr ...
- iOS 面试题 1
1. 简述OC中内存管理机制.与retain配对使用的方法是dealloc还是release,为什么?需要与alloc配对使用的方法是dealloc还是release,为什么?readwrite ...
- spring mvc ajax
<%@ page contentType="text/html;charset=UTF-8" %> <%@ include file="/WEB-INF ...
- (转)ubuntu下如何查看软件安装目录以及安装版本
1.查询版本 aptitude show 软件名 例如:aptitude show kde-runtime 显示如下: ****@ubuntu:~$ aptitude show kde-runtime ...
- Delphi 接口托管实现
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- FTP之主动模式vs被动模式
背景说明 最近有个项目涉及到FTP的上传下载问题.在本地开发好的程序测试的时候能正常获取FTP内容,但一放到生产上却显示connection timeout,无法连接.经过一些研究,发现是防火墙造成的 ...
- yii2中的url美化
在yii2中,如果想实现类似于post/1,post/update/1之类的效果,官方文档已经有明确的说明 但是如果想把所有的controller都实现,这里采用yii1的方法 'rules' =&g ...
- python笔记之编程风格大比拼
python笔记之编程风格大比拼 虽然我的python age并不高,但我仍然愿意将我遇到的或者我写的有趣的python程序和大家一块分享,下面是我找到的一篇关于各类python程序员的编程风格的比较 ...
- SQL Sever 各版本下载 SQL Server 2012下载SQL Server 2008下载SQL Server 2005
SQL Server 2012SQL Server 2012 开发版(DVD)(X64,X86)(中文简体)ed2k://|file|cn_sql_server_2012_developer_edit ...
- 常用两种数据交换格式之XML和JSON的比较
目前,在web开发领域,主要的数据交换格式有XML和JSON,对于XML相信每一个web developer都不会感到陌生: 相比之下,JSON可能对于一些新步入开发领域的新手会感到有些陌生,也可能你 ...