IOS SDK
(→SDK使用说明) |
(→接口说明) |
||
第56行: | 第56行: | ||
==接口说明== | ==接口说明== | ||
Class: WBEngine | Class: WBEngine | ||
− | + | ||
+ | |||
+ | '''1、获取WBEngine实例''' 初始化WBEngine类 | ||
+ | |||
+ | 接口名称: (id)initWithAppKey:(NSString*)app_key withAppSecret:(NSString*)app_secret | ||
+ | |||
+ | <table class="wiki_table" border="0" cellspacing="0" cellpadding="0" style="width:100%"> | ||
+ | <tr> | ||
+ | <th class="wiki_table_thfirst" style="width:150px">参数名称 | ||
+ | </th><th>作用 | ||
+ | </th></tr> | ||
+ | <tr> | ||
+ | <td class="wiki_table_tdfirst">App_key | ||
+ | </td><td>申请应用时分配给第三方应用程序的App key。 | ||
+ | </td></tr> | ||
+ | <tr> | ||
+ | <td class="wiki_table_tdfirst">App_secret | ||
+ | </td><td>申请应用时分配给第三方应用程序的App secrect。 | ||
+ | </td></tr> | ||
+ | </table> | ||
+ | 返回结果:返回WBEngine类的实例。 | ||
+ | |||
+ | |||
+ | '''2、Web方式认证''' | ||
+ | *接口名称:(void)login | ||
+ | *返回结果:无 | ||
+ | |||
+ | |||
+ | '''3、客户端方式认证''' | ||
+ | *使用SDK提供的默认界面发送微博 | ||
+ | *接口名称: (void)logInUsingUserID:(NSString *)theUserID password:(NSString *)thePassword | ||
+ | |||
+ | <table class="wiki_table" border="0" cellspacing="0" cellpadding="0" style="width:100%"> | ||
+ | <tr> | ||
+ | <th class="wiki_table_thfirst" style="width:150px">参数名称 | ||
+ | </th><th>作用 | ||
+ | </th></tr> | ||
+ | <tr> | ||
+ | <td class="wiki_table_tdfirst">TheUserID | ||
+ | </td><td>用户登陆名称。 | ||
+ | </td></tr> | ||
+ | <tr> | ||
+ | <td class="wiki_table_tdfirst">ThePassword | ||
+ | </td><td>用户密码。 | ||
+ | </td></tr> | ||
+ | </table> | ||
+ | 返回结果:无。 | ||
+ | |||
+ | |||
+ | '''4、通过接口发送微博''' | ||
+ | *接口名称:(void)sendWeiBoWithText:(NSString *)text image:(UIImage *)image | ||
+ | |||
+ | <table class="wiki_table" border="0" cellspacing="0" cellpadding="0" style="width:100%"> | ||
+ | <tr> | ||
+ | <th class="wiki_table_thfirst" style="width:150px">参数名称 | ||
+ | </th><th>作用 | ||
+ | </th></tr> | ||
+ | <tr> | ||
+ | <td class="wiki_table_tdfirst">Text | ||
+ | </td><td>发送的微博内容。 | ||
+ | </td></tr> | ||
+ | <tr> | ||
+ | <td class="wiki_table_tdfirst">Image | ||
+ | </td><td>发送的微博图片。 | ||
+ | </td></tr> | ||
+ | </table> | ||
+ | 返回结果:无。 | ||
+ | |||
+ | |||
+ | '''5、自定义请求''' | ||
+ | *接口名称: (void)loadRequestWithMethodName:(NSString *)methodName | ||
+ | httpMethod:(NSString *)httpMethod | ||
+ | params:(NSDictionary *)params | ||
+ | postDataType:(WBRequestPostDataType)postDataType | ||
+ | httpHeaderFields:(NSDictionary *)httpHeaderFields | ||
+ | |||
+ | <table class="wiki_table" border="0" cellspacing="0" cellpadding="0" style="width:100%"> | ||
+ | <tr> | ||
+ | <th class="wiki_table_thfirst" style="width:150px">参数名称 | ||
+ | </th><th>作用 | ||
+ | </th></tr> | ||
+ | <tr> | ||
+ | <td class="wiki_table_tdfirst">MethodName | ||
+ | </td><td>url中除去http://api.t.sina.com.cn/的部分。 | ||
+ | </td></tr> | ||
+ | <tr> | ||
+ | <td class="wiki_table_tdfirst">HttpMethod | ||
+ | </td><td>GET or POST。 | ||
+ | </td></tr> | ||
+ | <tr> | ||
+ | <td class="wiki_table_tdfirst">Params | ||
+ | </td><td>发送的参数集合。 | ||
+ | </td></tr> | ||
+ | <tr> | ||
+ | <td class="wiki_table_tdfirst">PostDataType | ||
+ | </td><td>Post里面的数据类型,图片,文字。 | ||
+ | </td></tr> | ||
+ | <tr> | ||
+ | <td class="wiki_table_tdfirst">Delegate | ||
+ | </td><td>发送请求的代理对象,用来接收发送请求的各种回调方法。 | ||
+ | </td></tr> | ||
+ | </table> | ||
+ | 返回结果:无。 |
2012年2月13日 (一) 19:44的版本
目录 |
概述
微博官方SDK提供给开发者OAuth认证,发送微博和其他Open API URL请求,默认的发送界面,数据解析等功能。 目前支持iOS 4.0以上系统,发送界面暂不支持IPAD设备。
名词解释
参数名称 | 作用 |
---|---|
Consumer_key | 分配给每个第三方应用的App key。用于鉴权身份,显示来源等功能。 |
Consumer_secret | 生成请求Request Token的Secret,与Consumer key一起分配。 |
OAuth_token | 服务器根据App key和时间,Callback_url等哈希出的Token值,用于获取OAuth verifier。 |
OAuth_token_secret | 与OAuth Token一起使用,用于获取OAuth verifier。 |
OAuth_verifier | 通过OAuth页面返回的verifier,用于最终获取Access Token。 |
Access_token | 表示用户身份的Token,用于微博API的调用。 |
授权模式
OAuth2.0,支持web授权和客户端授权两种模式。
整体架构
- 整体架构图:[1]
- 主要结构说明:
- 1、Weibo: 微博API 接口类,对外提供Weibo API的调用,包括登录,API调用,微博分享等功能。
- 2、AsyncWeiboRunner:微博API异步执行类,封装了回调接口,通过创建线程来调用Weibo中的接口方法。
- 3、Utility:互联网工具类,包括接口请求GET/POST封装,BASE64等encode,decode方法。
- 4、WeiboException:微博异常封装类,封装了微博的各个异常。
SDK使用说明
- 1、安装Xcode。
- 2、从open.weibo.com下载官方SDK包。
- 3、SDK包里面包含有示例程序和SDK的源代码。打开SinaWeiBoSDK/src下面的SDK工程,将其中的src文件夹拖拽到自己的工
- 程里面。
- 4、在自己的工程里面增加Security.framework。SDK需要使用Security.framework将OAuth认证以后的Token放到KeyChain里面
- 从而增加整个工程的安全性。
- 5、到 http://open.weibo.com/ 创建新的应用,获取相应的App Key 和 App Secrect。
- 6、SDK使用及修改必须遵守微博开发者协议,以及开源软件协议。
接口说明
Class: WBEngine
1、获取WBEngine实例 初始化WBEngine类
接口名称: (id)initWithAppKey:(NSString*)app_key withAppSecret:(NSString*)app_secret
参数名称 | 作用 |
---|---|
App_key | 申请应用时分配给第三方应用程序的App key。 |
App_secret | 申请应用时分配给第三方应用程序的App secrect。 |
返回结果:返回WBEngine类的实例。
2、Web方式认证
- 接口名称:(void)login
- 返回结果:无
3、客户端方式认证
- 使用SDK提供的默认界面发送微博
- 接口名称: (void)logInUsingUserID:(NSString *)theUserID password:(NSString *)thePassword
参数名称 | 作用 |
---|---|
TheUserID | 用户登陆名称。 |
ThePassword | 用户密码。 |
返回结果:无。
4、通过接口发送微博
- 接口名称:(void)sendWeiBoWithText:(NSString *)text image:(UIImage *)image
参数名称 | 作用 |
---|---|
Text | 发送的微博内容。 |
Image | 发送的微博图片。 |
返回结果:无。
5、自定义请求
- 接口名称: (void)loadRequestWithMethodName:(NSString *)methodName
httpMethod:(NSString *)httpMethod params:(NSDictionary *)params postDataType:(WBRequestPostDataType)postDataType httpHeaderFields:(NSDictionary *)httpHeaderFields
参数名称 | 作用 |
---|---|
MethodName | url中除去http://api.t.sina.com.cn/的部分。 |
HttpMethod | GET or POST。 |
Params | 发送的参数集合。 |
PostDataType | Post里面的数据类型,图片,文字。 |
Delegate | 发送请求的代理对象,用来接收发送请求的各种回调方法。 |
返回结果:无。