IOS 6社交应用开发-新浪微博
2013-05-23 08:49
281 查看
原始地址:IOS 6社交应用开发-新浪微博
1.添加Framework.
2.导入头文件.
3.确保在“设置”里配置了社交应用的帐户(以新浪微博举例),如下图。
4.获取新浪微博用户.
5.发布微博.
新浪微博接口文档
1.添加Framework.
2.导入头文件.
#import <Accounts/Accounts.h> #import <Social/Social.h>
3.确保在“设置”里配置了社交应用的帐户(以新浪微博举例),如下图。
4.获取新浪微博用户.
//获取帐号存储 ACAccountStore *strore = [[ACAccountStore alloc] init]; //获取新浪微博的帐号类型 ACAccountType *type = [strore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierSinaWeibo]; //验证是否配置了匹配帐户 [strore requestAccessToAccountsWithType:type options:nil completion:^(BOOL granted, NSError *error) { if (granted)//验证授权成功 { //获取新浪微博用户列表 NSArray *counts = [strore accountsWithAccountType:type]; if (counts && [counts count] > 0) { //认证通过 //以第一个用户举例 [self requestWithAccount:[counts objectAtIndex:0]]; } } }];
5.发布微博.
新浪微博接口文档
- (void)requestWithAccount:(ACAccount *)account { /* //类型 SLServiceTypeTwitter SLServiceTypeFacebook SLServiceTypeSinaWeibo //方法 SLRequestMethodGET SLRequestMethodPOST SLRequestMethodDELETE */ //请求地址,参考上图 NSURL *url = [NSURL URLWithString:@"https://open.weibo.cn/2/statuses/update"]; //配置参数字典 NSDictionary *para = [NSDictionary dictionaryWithObjectsAndKeys:@"ssstext", @"status", nil]; //配置轻取 SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeSinaWeibo requestMethod:SLRequestMethodGET URL:url parameters:para]; //装载微博用户 request.account = account; //发送微博 [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { if (!error) { //主线程中操作UI dispatch_async(dispatch_get_main_queue(), ^{ NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; NSLog(@"请求结果:%@",response); //操作UI }); } }]; }
相关文章推荐
- iOS开发笔记1:ToDoList、相册、地图应用及新浪微博
- 类簇在iOS开发中的应用
- iOS开发中arc的设置与应用
- 2011斯坦福大学iOS应用开发教程学习笔记(第三课)Objective-C
- 支持iOS平台设备上的音频即时通讯应用开发
- iOS开发-应用性能调优的25个建议和技巧
- iOS 11开发教程(十二)iOS11应用视图始祖——UIView
- ios xmpp开发应用后台模式接收聊天信息
- 新浪微博应用开发的又一个解决方案
- 类簇在iOS开发中的应用
- iOS开发之应用首次启动显示用户引导
- IOS应用开发-图片处理
- 2011斯坦福大学iOS应用开发教程学习笔记(第二课)My First iOS App
- ios-新浪微博开发07-自定义搜索框
- ios开发系列之应用的后台处理
- Runtime在iOS开发中的实际应用
- ios开发中地图应用
- iOS开发系列--让你的应用“动”起来
- iOS 9应用开发教程之ios9中实现按钮的响应
- iOS开发--底部按钮和应用图标显示未读消息