新浪微博登录SDK

导入libsqlite3.tbd-----adSupport.framework------ImageIO.framework---JAVAScriptCore.framework

libstdc++.tbd---------libz.tbd----libicucore.tbd

//新浪微博SDK需要在项目Build Settings中的Other Linker Flags添加"-ObjC"


新版本在Infor.plist  中添加App transport.....中添加Allow...把后面的NO改为YES 

将SDK导入

Appdelegate  导入头文件

#import <ShareSDK/ShareSDK.h>

#import <ShareSDKConnector/ShareSDKConnector.h>

#import "WeiboSDK.h"

#import "ViewController.h"


   // Override point for customization after application launch.

    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设置为使用SSOWeb形式授权

                 [appInfo SSDKSetupSinaWeiboByAppKey:@"568898243"

                                           appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"

                                         redirectUri:@"http://www.sharesdk.cn"

                                            authType:SSDKAuthTypeBoth];

                 break;

          

             default:

                 break;

         }

     }];


在ViewControllers.m中加入头文件

#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;

}


- (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];

    

}




转载于:https://my.oschina.net/zhaofengye/blog/596560

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值