[iOS微博项目 - 3.2] - 发送微博



1 // HVWComposeViewController.m
2 /** 发送微博 */
3 - (void) sendWeibo {
4 if (self.composeView.text.length == 0) {
5 [MBProgressHUD showError:@"你好像忘记了内容..."];
6 return;
7 }
8
9 [MBProgressHUD showMessage:@"发送微博中..."];
10
11 if (self.imageDisplayView.images.count) { // 发送的时带图片的微博
12 [self sendWeiboWithTextNImage];
13 } else { // 发送的是纯文字微博
14 [self sendWeiboWithText];
15 }
16 }
17
18 /** 发送文字微博 */
19 - (void) sendWeiboWithText {
20 // 创建http操作管理者
21 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
22
23 // 设置参数
24 NSMutableDictionary *param = [NSMutableDictionary dictionary];
25 // 访问令牌
26 HVWAccountInfo *accountInfo = [HVWAccountInfoTool accountInfo];
27 param[@"access_token"] = accountInfo.access_token;
28 // 微博文本
29 param[@"status"] = self.composeView.text;
30
31 // 发送请求
32 [manager POST:@"https://api.weibo.com/2/statuses/update.json" parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
33 [MBProgressHUD hideHUD];
34 [MBProgressHUD showSuccess:@"发送成功!"];
35 } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
36 HVWLog(@"发送微博失败, error:%@", error);
37 [MBProgressHUD hideHUD];
38 [MBProgressHUD showError:@"发送失败!error"];
39 }];
40 }
41
42 /** 发送图文微博 */
43 - (void) sendWeiboWithTextNImage {
44 if (self.imageDisplayView.images.count == 0) {
45 [MBProgressHUD hideHUD];
46 [MBProgressHUD showError:@"懵了,找不到图儿!"];
47 return;
48 }
49
50 // 创建http操作管理者
51 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
52
53 // 设置参数
54 NSMutableDictionary *param = [NSMutableDictionary dictionary];
55 // 访问令牌
56 HVWAccountInfo *accountInfo = [HVWAccountInfoTool accountInfo];
57 param[@"access_token"] = accountInfo.access_token;
58 // 微博文本
59 param[@"status"] = self.composeView.text;
60
61 // 发送请求
62 [manager POST:@"https://upload.api.weibo.com/2/statuses/upload.json" parameters:param constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
63
64 // 发送的图片数据,其实现在开放的API只允许上传一张图片
65 UIImage *image = [self.imageDisplayView.images firstObject];
66 if (image) {
67 NSData *imageData = UIImagePNGRepresentation(image);
68 [formData appendPartWithFileData:imageData name:@"pic" fileName:@"statusPic" mimeType:@"image/png"];
69 }
70 } success:^(AFHTTPRequestOperation *operation, id responseObject) {
71 [MBProgressHUD hideHUD];
72 [MBProgressHUD showSuccess:@"发送成功!"];
73 } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
74 HVWLog(@"发送微博失败, error:%@", error);
75 [MBProgressHUD hideHUD];
76 [MBProgressHUD showError:@"发送失败!"];
77 }];
78 }

[iOS微博项目 - 3.2] - 发送微博的更多相关文章
- AJ学IOS 之微博项目实战(13)发送微博调用相机里面的图片以及调用相机
AJ分享,必须精品 一:效果 二:代码 相机部分就简单多了,几行代码调用而已,但是如果你要是想实现更多丰富的功能,需要自己写.利用AssetsLibrary.framework,利用这个框架可以获得手 ...
- AJ学IOS 之微博项目实战(12)发送微博自定义工具条代理实现点击事件
AJ分享,必须精品 一:效果 二:封装好的工具条 NYComposeToolbar.h 带代理方法 #import <UIKit/UIKit.h> typedef enum { NYCom ...
- AJ学IOS 之微博项目实战(11)发送微博自定义TextView实现带占位文字
AJ分享,必须精品 一:效果 二:代码: 由于系统自带的UITextField:和UITextView:不能满足我们的需求,所以我们需要自己设计一个. UITextField: 1.文字永远是一行,不 ...
- QQ登入(6)腾讯微博-获取微博用户信息,发送微博
1.1获取weibo用户信息 //先登入授权,可以参考QQ登入(1) Weibo mWeibo = new Weibo(this, mQQAuth.getQQToken()); mWeibo.getW ...
- [iOS微博项目 - 2.6] - 获取微博数据
github: https://github.com/hellovoidworld/HVWWeibo A.新浪获取微博API 1.读取微博API 2.“statuses/home_time ...
- [iOS微博项目 - 4.0] - 自定义微博cell
github: https://github.com/hellovoidworld/HVWWeibo A.自定义微博cell基本结构 1.需求 创建自定义cell的雏形 cell包含:内容.工具条 内 ...
- [iOS微博项目 - 3.1] - 发微博界面
github: https://github.com/hellovoidworld/HVWWeibo A.发微博界面:自定义UITextView 1.需求 用UITextView做一个编写微博的输 ...
- 使用新版SDK不想跳转微博客户端能否直接发送微博分享?
如题啊如题! 新版本中没有StatusesAPI?????
- Android应用内使用新浪微博SDK发送微博(不调用微博客户端)
需求 手头的一个应用需要添加分享到新浪微博的功能,这个功能在现在的应用上是非常的普遍的了. 分享到新浪微博,其实就是发送一条特定内容的微博,所以需要用到新浪微博SDK了. 微博SDK SDK的下载地址 ...
随机推荐
- 51nod1537 分解
http://blog.csdn.net/qingshui23/article/details/52350523 详细题解%%%%对矩阵乘法的不熟悉.以及不会推公式 #include<cstdi ...
- vim 大小写转化命令
vim中大小写转化的命令是<blockquote>gu或者gU</blockquote>形象一点的解释就是小u意味着转为小写:大U意味着转为大写. 剩下的就是对这两个命令的限定 ...
- 搭建 MPICH3 并行计算环境
先记录在单机MacBook上的搭建,实验室集群的搭建流程是一样的,不过每台机器都需要做一次. MacBook: 1.安装mpich3: $ ./configure --prefix=/Users/xi ...
- Amarino例程无法使用的问题
Serial.begin(9600); 而不是用它的57600
- poj 1472(递归模拟)
题意:就是让你求出时间复杂度. 分析:由于指数最多为10次方,所以可以想到用一个数组保存各个指数的系数,具体看代码实现吧! 代码实现: #include<cstdio> #include& ...
- 十六进制字符串转化成字符串输出HexToStr(Delphi版、C#版)
//注意:Delphi2010以下版本默认的字符编码是ANSI,VS2010的默认编码是UTF-8,delphi版得到的字符串须经过Utf8ToAnsi()转码才能跟C#版得到的字符串显示结果一致. ...
- Python自动单元测试框架
原文链接:http://www.ibm.com/developerworks/cn/linux/l-pyunit/ 软件的测试是一件非常乏味的事情,在测试别人编写的软件时尤其如此,程序员通常都只对编写 ...
- int (*p)[4] p 是二级指针 二维数组 二级指针 .xml
pre{ line-height:1; color:#2f88e4; background-color:#e9ffff; font-size:16px;}.sysFunc{color:#3d7477; ...
- (转)Spring中Bean的命名问题(id和name区别)及ref和idref之间的区别
Spring中Bean的命名 1.每个Bean可以有一个id属性,并可以根据该id在IoC容器中查找该Bean,该id属性值必须在IoC容器中唯一: 2.可以不指定id属性,只指定全限定类名,如: & ...
- php连接数据库
<?php header('Content-Type:text/html; charset=utf-8'); define('DB_HOST', 'localhost'); define('DB ...