在进行SSO请求之前 我们要先去新浪微博的开放平台http://open.weibo.com/进行创建应用.以便得到appKey 和AppSecret.

点击创建应用 .进行资料填写  在这里

Apple ID 是现在可以随意填写的 但是在正式应用上线后 需要马上更改

Bundle ID  必须要和Xcode上的 Bundle Identifier 上的一样.1) 导入libWeiboSDK设置代理.WeiboSDKDelegate2)注册Appkey 
    [WeiboSDK enableDebugMode:YES];
    [WeiboSDK registerApp:kAppKey];
    3)创建一个Button用来触发sso请求//创建一个Button来点击请求授权
    
    _ssoButton=[UIButton buttonWithType:UIButtonTypeCustom];
   
   // [_ssoButton setTitle:@"hehehehe" forState:UIControlStateNormal];//要颜色啊
    [_ssoButton setImage:[UIImage imageNamed:@"LoginButton@2x.png"] forState:UIControlStateNormal];
    [_ssoButton addTarget:self action:@selector(ssoButtonRequest) forControlEvents:UIControlEventTouchDown];
    
    [_ssoButton setFrame:CGRectMake(100, 350, 130, 80)];
    
    
    [self.view addSubview:_ssoButton];

4)触发 发送授权请求-(void)ssoButtonRequest
{
    WBAuthorizeRequest*request=[WBAuthorizeRequest request];
    request.redirectURI=kRedirectURI;
    request.scope=@"all";
    request.userInfo = @{@"SSO_From": @"SendMessageToWeiboViewController",
                         @"Other_Info_1": [NSNumber numberWithInt:123],
                         @"Other_Info_2": @[@"obj1", @"obj2"],
                         @"Other_Info_3": @{@"key1": @"obj1", @"key2": @"obj2"}};
    [WeiboSDK sendRequest:request];
    
   
    
}5)接受weibo的响应  
- (void)didReceiveWeiboResponse:(WBBaseResponse *)response
{
    
    
    if ([response isKindOfClass:WBSendMessageToWeiboResponse.class])
    {
        NSString *title = @"发送结果";
        NSString *message = [NSString stringWithFormat:@"响应状态: %d\n响应UserInfo数据: %@\n原请求UserInfo数据: %@",
                             response.statusCode, response.userInfo, response.requestUserInfo];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                        message:message
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    else if ([response isKindOfClass:WBAuthorizeResponse.class])
    {
        NSString *title = @"认证结果";
        NSString *message = [NSString stringWithFormat:@"响应状态: %d\nresponse.userId: %@\nresponse.accessToken: %@\n响应UserInfo数据: %@\n原请求UserInfo数据: %@",
                             response.statusCode, [(WBAuthorizeResponse *)response userID], [(WBAuthorizeResponse *)response accessToken], response.userInfo, response.requestUserInfo];
        
        
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                        message:message
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        
        self.wbtoken = [(WBAuthorizeResponse *)response accessToken];
        
        NSLog(@"token=%@", self.wbtoken);
        // 保存授权用户的token   如果需要进行API请求 便要保存密钥
        [[NSUserDefaults standardUserDefaults] setObject:self.wbtoken forKey:@"access_token"];
        
        [alert show];
        [alert release];
    }

}

6)创建一个按钮 触发请求接口数据 (这里以请求200条公共微博为例子.默认20条)
   UIButton*requestDataButton=[UIButton buttonWithType:UIButtonTypeCustom];
    
   [requestDataButton setTitle:@"请求数据" forState:UIControlStateNormal];
    
   [requestDataButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
   [requestDataButton setBackgroundColor:[UIColor orangeColor]];
    
    [requestDataButton addTarget:self action:@selector(requestData) forControlEvents:UIControlEventTouchDown];
   [requestDataButton setFrame:CGRectMake(100, 420, 130, 80)];
    
   
    [self.view addSubview:requestDataButton];

7)用异步请求去请求并且解析 用到了SBJson第三方
-(void)requestData
{
    //创建密钥的字符串
    NSString*access_token=[[NSUserDefaults standardUserDefaults]objectForKey:@"access_token"];
   
    
    //创建一个URL...
    NSURL*url=[NSURL URLWithString:[NSString stringWithFormat:@"https://api.weibo.com/2/statuses/public_timeline.json?access_token=%@",access_token]];
   
    //创立一个request对象
    NSURLRequest*request=[NSURLRequest requestWithURL:url];
    
    //实例化一个可变的data 用来接受数据
    _data=[[NSMutableData alloc]init];
    
    //设置一个异步连接请求
    
    
    [NSURLConnection connectionWithRequest:request delegate:self];

}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    NSLog(@"hehhe");
    
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    //进行拼接
    
    [_data appendData:data];
    NSLog(@"=========%d",_data.length);
    
    
    
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    
    NSString*dataStr=[[NSString alloc]initWithData:_data encoding:NSUTF8StringEncoding];
    
    
    NSDictionary*dataJS=[dataStr JSONValue  ];
    NSLog(@"datajs=%@",dataJS);
    
    
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    
    
    NSLog(@"有错误");
    
}

8)/********
 
 重写AppDelegate 的 handleOpenURL 和 openURL 方法
 
 *********/

//写上面即可...

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    
    
    return [WeiboSDK handleOpenURL:url delegate:self];
}

-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    
    return [WeiboSDK handleOpenURL:url delegate:self];
}

//这个sdk里面的请求是调用了手机内的微博app .

[WBHttpRequest requestWithAccessToken:kDefineToken url:@"https://api.weibo.com/2/statuses/public_timeline.json" httpMethod:@"GET" params:nil delegate:self withTag:nil];

Weibo SSO认证 和初次请求数据的更多相关文章

  1. 前端缓存API请求数据

    1. 背景 在一些项目中,有时候会出现不同模块重复请求大量相同api接口的情况,特别是在一些功能相似的后台管理页面中.以下面这几个页面为例,每次进入页面都需要请求等大量重复的下拉框数据,下拉框数据短时 ...

  2. (转)《SSO CAS单点系列》之 实现一个SSO认证服务器是这样的!

    上篇我们引入了SSO这个话题<15分钟了解SSO是个什么鬼!>.本篇我们一步步深入分析SSO实现机理,并亲自动手实现一个线上可用的SSO认证服务器!首先,我们来分析下单Web应用系统登录登 ...

  3. HTTP客户端之使用request方法向其他网站请求数据

    在node中,可以很轻松的向任何网站发送请求并读取该网站的响应数据. var req=http.request(options,callback); options是一个字符串或者是对象.如果是字符串 ...

  4. iOS 绕过https证书验证 请求数据

    HTTPS和HTTP: 1.https协议需要到ca申请证书,一般免费证书很少,需要交费. 2.http是超文本传输协议,信息是明文传输,https 则是具有安全性的ssl加密传输协议. 3.http ...

  5. Django-REST-Framework JWT 实现SSO认证(上)

    一.什么是Django-REST-Framework? Django-REST-framework 是基于Django框架的一个web RESTful风格开发的框架,它可以实现API接口的快速开发,但 ...

  6. C# http请求数据

    http中get和post请求的最大区别:get是通过URL传递表单值,post传递的表单值是隐藏到 http报文体中 http以get方式请求数据 /// <summary> /// g ...

  7. 【原生态】Http请求数据 与 发送数据

    今天项目组小弟居然问我怎么用java访问特定的地址获取数据和发送请求 Http请求都是通过输入输出流来进行操作的,首先要制定GET或者POST,默认是GET,在安全和数据量较大情况下请使用post 根 ...

  8. 用JQuery Ajax 与一般处理程序 请求数据无刷新,以及如何调试错误

    通过 ajax() 与 一般处理程序,请求数据库数据,实现界面无刷新. Jquery ajax 请求参数详细说明 http://www.w3school.com.cn/jquery/ajax_ajax ...

  9. Java服务器对外提供接口以及Android端向服务器请求数据

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/5056780.html 讲解下java服务器是如何对移动终端提供接口的,以什么数据格式提供出去,移动端又是怎么 ...

随机推荐

  1. Fedora上配置一个安全FTP

    现在流行的FTP服务器,比较著名的有WU-FTP(Washington University FTP)和VSFTP(Very Secure FTP 非常安全的FTP)以及Proftp,pureftp等 ...

  2. 常用jQuery选择器总结【转】

    在Dom 编程中我们只能使用有限的函数根据id 或者TagName 获取Dom 对象. 然而在jQuery 中则完全不同,jQuery 提供了异常强大的选择器用来帮助我们获取页面上的对象, 并且将对象 ...

  3. Apache:To Config The Vhost of Django Project

    It is not a good idea to use dev server in Production Environment. Apache or Nginx are good choice.B ...

  4. MVC身份验证及权限管理

    MVC自带的ActionFilter 在Asp.Net WebForm的中要做到身份认证微软为我们提供了三种方式,其中最常用的就是我们的Form认证,需要配置相应的信息.例如下面的配置信息: < ...

  5. ubuntu 设置root启动

    http://www.linuxidc.com/Linux/2012-05/60806.htm sudo -s 输入普通用户的password 回车即可进入root权限 vi /etc/lightdm ...

  6. 智能硬件开发如何选择低功耗MCU

    本文将市场上典型的低功耗MCU系列进行了比较,分析得出基于ARM. Cortex M0+内核的MCU系列最适合穿戴式医疗设备的开发.设备开发者当密切关注其发展动向,结合现有的市场需求.产品体系的构建和 ...

  7. 以不同用户身份运行程序,/savecred只需要输入一次密码(GetTokenByName取得EXPLORER.EXE的令牌,然后调用CreateProcessAsUser,而且使用LoadUserProfile解决另存文件的问题)good

    http://blog.sina.com.cn/s/blog_65977dde0100s7tm.html ----------------------------------------------- ...

  8. 模拟键盘发送文字(使用SendInput函数)

    嗯...老生常谈的话题, 不过系统的总结了一下, 找了个相对简单的实现方式, 可以方便的发送任何文字 参考另一片文章: http://www.cnblogs.com/-clq/archive/2011 ...

  9. CBO学习笔记(转)

    Query Transformation 在继续研究SQL的其他操作(比如Join)对CBO的影响之前,我们来讨论一下Oracle优化器的Query Transformation特性.我们都习惯于根据 ...

  10. scheme和common lisp 区别

    Scheme and Common Lisp use different names for some of the basic system functions. Many Lisp program ...