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示例,登录,获取个人信息的更多相关文章

  1. 最简单的基于DirectShow的示例:获取Filter信息

    ===================================================== 最简单的基于DirectShow的示例文章列表: 最简单的基于DirectShow的示例:视 ...

  2. Android之QQ授权登录获取用户信息

    有时候我们开发的app须要方便用户简单登录.能够让用户使用自己的qq.微信.微博登录到我们自己开发的app. 今天就在这里总结一下怎样在自己的app中集成QQ授权登录获取用户信息的功能. 首先我们打开 ...

  3. uni-app开发经验分享二十: 微信小程序 授权登录 获取详细信息 获取手机号

    授权页面 因为微信小程序提供的 权限弹窗 只能通用户确认授权 所以可以 写一个授权页面,让用户点击 来获取用户相关信息 然后再配合后台就可以完成登录 <button class="bt ...

  4. iOS 整理笔记 获取手机信息(UIDevice、NSBundle、NSLocale)

    /*    iOS的APP的应用开发的过程中,有时为了bug跟踪或者获取用反馈的需要自动收集用户设备.系统信息.应用信息等等,这些信息方便开发者诊断问题,当然这些信息是用户的非隐私信息,是通过开发ap ...

  5. [转载]iOS开发:获取设备信息

    开发iOS平台的应用的时候,可以获取iOS设备的设备信息,包括设备的名称,设备的机型,设备的iOS版本等等.设备信息主要来自 UIDevice 类. UIDevice *currentDevice = ...

  6. 微信第三方登陆,无需注册一键登录,获取用户信息,PHP实现方法

    今天讲讲利用微信oauth2实现第三方登陆的实现方法. 先说说前提吧! 首先你得是服务号,并且是经过认证的.这样微信会给你很多第三方接口的权限,如果是订阅号或者没有认证的服务号那就不用想了! 一开始你 ...

  7. Python入门小练习 003 利用cookielib模拟登录获取账户信息

    为了方便, 使用chinaunix的账户获取账户主题. 有些网站可能需要验证码,  找一些不用验证码的网站 下面 ****** 很多个星号的均为私密信息, 所以用星号代替 #!/usr/bin/pyt ...

  8. app支付宝授权登录获取用户信息

    由后台进行地址的拼接(前台进行授权) // 生成授权的参数 String sign = ""; Long userId1 = SecurityUser.getUserId(); S ...

  9. Laravel wxxcx 微信小程序获取用户信息

    wxxcx 是Laravel5微信小程序登录获取用户信息扩展 部署 12345678 # 安装$ composer require iwanli/wxxcx# 注册服务# 在 /config/app. ...

随机推荐

  1. Margin是什么?

    Margin是什么 CSS 边距属性定义元素周围的空间.通过使用单独的属性,可以对上.右.下.左的外边距进行设置.也可以使用简写的外边距属性同时改变所有的外边距.——W3School 边界,元素周围生 ...

  2. GDI+创建Graphics对象的2种方式

      1.this.CreateGraphics()     // 调用控件的CreateGraphics()方法 2.在OnPaint事件中,PaintEventArgs类型的参数e对象的Graphi ...

  3. Global.asax使用2

    ASP.NET中利用Application和Session统计在线人数.历史访问量 先来简单说一下ASP.NET中的Application和Session 下图是我们非常熟悉的Web应用程序的结构: ...

  4. html表格,列表

    1. 表格由 <table> 标签来定义.每个表格均有若干行(由 <tr> 标签定义),每行被分割为若干单元格(由 <td> 标签定义).字母 td 指表格数据(t ...

  5. C#遍历数组

    Eg: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...

  6. ES6 let和const命令

    一.let定义变量 { let a = 1;} console.log(a);只在let所在的代码块有效,console的结果是a is not defined,报错. 不存在var的变量提升,即使用 ...

  7. 剑指offier第三题

    package 剑指office; /* * 第三题二维数组查找 * 在一个二维数组中,每一行都按照从左到右递增的顺序排序, * 每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维 ...

  8. (转)ubuntu 文件目录结构

    文件系统的类型 LINUX有四种基本文件系统类型:普通文件.目录文件.连接文件和特殊文件,可用file命令来识别. 1. 普通文件:如文本文件.C语言元代码.SHELL脚本.二进制的可执行文件等,可用 ...

  9. UVA 11754 Code Feat (枚举,中国剩余定理)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud C Code Feat   The government hackers at C ...

  10. [Leetcode] Find the minimum in rotated sorted array

    我在Github上新建了一个解答Leetcode问题的Project, 大家可以参考, 目前是Java 为主,里面有leetcode上的题目,解答,还有一些基本的单元测试,方便大家起步. 题目: Su ...