微博开发平台SDK使用示例(iOS版)
来源:互联网 发布:经典译林怎么样 知乎 编辑:程序博客网 时间:2024/06/05 11:50
为了提高应用的交互和扩散能力,引人微博或者QQ开放平台是个不错的选择。今天跟大家分享下微博开放平台SDK使用的示例。
首先,需要成为微博开放平台的开发者用户,然后可以新建应用,注意应用名称;
接下来,继续完善相应的应用信息,如Apple ID,测试阶段可以随意填写,Bundle ID必须和项目设置一致;记下AppKey需要在程序中用到
其次还需要在高级信息中设置回调页面(OAuth2.0授权),注意SDK文档里面的默认回调页面没有成功,可以设置成任意能够访问的页面即可,如http://www.baidu.com
回调页面设置不一致授权获取会如下提示:
完成以上设置就相当于在微博开放平台中注册了开发者应用的相关信息,接下来只需要下载SDK即可,页面如下
代码部分:
新建项目设置项目名称、Bundle Identifier和微博开放平台设置一致,并导人相应的SDK文件
在应用程序代理.h文件中添加WeiboSDK.h应用和相应协议
#import <UIKit/UIKit.h>#import "WeiboSDK.h"#define kAppKey @"1617942800"#define kRedirectURI @"http://www.baidu.com"@interface gisxyAppDelegate : UIResponder <UIApplicationDelegate,WeiboSDKDelegate>@property (strong, nonatomic) UIWindow *window;@property (strong, nonatomic) NSString *wbtoken;@end在应用程序的代理.m文件中设置开启调试和注册应用(Appkey)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ // Override point for customization after application launch. [WeiboSDK enableDebugMode:YES]; [WeiboSDK registerApp:kAppKey]; return YES;}在合适的位置添加授权请求
-(IBAction)sinaAuth:(id)sender{ WBAuthorizeRequest *request = [WBAuthorizeRequest request]; request.redirectURI = @"http://www.baidu.com"; request.scope = @"all"; request.userInfo = @{@"SSO_From": @"gisxyViewController", @"Other_Info":@"gisxy"}; [WeiboSDK sendRequest:request];}重写应用程序代理的OpenURL
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{ NSLog(@"ur %@",url); return [WeiboSDK handleOpenURL:url delegate:self];}实现WeiboSDKDelegate协议,设置请求相应处理
- (void)didReceiveWeiboResponse:(WBBaseResponse *)response{ if ([response isKindOfClass:WBSendMessageToWeiboResponse.class]) { NSString *title = @"发送结果"; NSString *message = [NSString stringWithFormat:@"响应状态: %d\n响应UserInfo数据: %@\n原请求UserInfo数据: %@",(int)response.statusCode, response.userInfo, response.requestUserInfo]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; } else if ([response isKindOfClass:WBAuthorizeResponse.class]) { NSString *title = @"认证结果"; NSString *message = [NSString stringWithFormat:@"响应状态: %d\nresponse.userId: %@\nresponse.accessToken: %@\n响应UserInfo数据: %@\n原请求UserInfo数据: %@",(int)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 is %@",[(WBAuthorizeResponse *)response accessToken]); [alert show]; }}- (void)didReceiveWeiboRequest:(WBBaseRequest *)request{ if ([request isKindOfClass:WBProvideMessageForWeiboRequest.class]) { // view *controller = [[ProvideMessageForWeiboViewController alloc] init]; // [self.viewController presentModalViewController:controller animated:YES]; NSLog(@"logs is sina"); }}完成以上,微博开放平台基本就可以正常使用啦,请求响应获取到accessToken 是关键。
对于文档中提到的设置工程回调URL Scheme貌似不设置也可以。
0 0
- 微博开发平台SDK使用示例(iOS版)
- [IOS开发] 微博开发平台SDK使用示例(iOS版)
- IOS 即时通讯开发平台(SDK)
- 开发腾讯移动游戏平台SDK ios版Ane扩展
- 微博开放平台SDK使用
- 使用蒲公英平台测试iOS APP(示例)
- iOS APP开发集成Apple Pay与银联SDK开发教程(附示例代码)
- iOS 平台项目接入新浪微博 SDK 的坑
- iOS 平台项目接入新浪微博 SDK 的坑
- IOS 腾讯微博开放平台 SDK 初体验
- Unity3D开发 - Unity3d与iOS交互开发(接入平台SDK)
- 新浪微博开发平台接入流程(2)---SDK Demo
- 平台:VS2010+object2015(sdk)+zwCAD2015(开发版) 配置
- (iOS开发)百度地图SDK使用以及学习
- PI-SDK开发示例
- 微信开放平台开发(微信iOS终端SDK新手使用指南)
- 开发腾讯移动游戏平台SDK ios版Ane扩展 总结
- IOS Android 视频播放(不使用第三方库,使用平台底层sdk)实现
- DHCP移植
- 云平台中虚拟机实例 root分区大小的自动扩充
- eclipse各种快捷键
- java cve
- Dlink DIR-615L 和 Mercury MW300R WDS 应用举例
- 微博开发平台SDK使用示例(iOS版)
- Apache Shiro 使用手册
- 防止头文件的重复包含和编译及重定义错误(ifndef/define/endif 用法)
- Java GUI编程(二)事件模型
- R Programming -- Factors
- 采用 C 标准库头文件的 C++ 版本(c++primer)
- object-c中的内存管理
- 用随机森林模型替代常用的回归和分类模型
- python3文本文件按行哈希