[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的下载地址 ...
随机推荐
- 51nod1239 欧拉函数之和
跟1244差不多. //由于(x+1)没有先mod一下一直WA三个点我... //由于(x+1)没有先mod一下一直WA三个点我... #include<cstdio> #include& ...
- BZOJ 1803 Query on a tree III
树上主席树. 我靠这是第k小吧..... #include<iostream> #include<cstdio> #include<cstring> #includ ...
- ecshop 更新首页flash样式
未测试 ECSHOP默认的只有几种很普通的FLASH图片切换样式,想不想自己也换一种呢? 今天摸索了下,算是弄懂了,和大家分享下 首先在网上找到你想要的FLASH切换样式[google一下],把那个S ...
- SQLServer如何快速生成100万条不重复的随机8位数字
最近在论坛看到有人问,如何快速生成100万不重复的8位编号,对于这个问题,有几点是需要注意的: 1. 如何生成8位随机数,生成的数越随机,重复的可能性当然越小 2. 控制不重复 3. ...
- 502 Bad Gateway nginx 解决
打开 /usr/local/php/etc/php-fpm.conf 调大以下两个参数(根据服务器实际情况,过大也不行) <value name=”max_children”>5120&l ...
- android LinearLayout 实现两端对齐
<?xml version="1.0″ encoding="utf-8″?> <LinearLayout xmlns:android="http://s ...
- delphi 中 $是什么意思 串口中使用
delphi 中 $是什么意思? 比如:$41----$5A 意识是26个字母, 可以用$来表示? $在delphi 中还可以怎么用?1.表示16进制,$41就是65,第一个字母的ASCII值 pro ...
- 转来的 cuda makefile 写法学习
原文作者:FreeAquar 原文出处:http://www.cnblogs.com/FreeAquar/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给 ...
- 【LeetCode】6 - ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- 11个实用经典的SQL小贴士
学习工作之余,在没有要解决问题的压力之下,还是建议系统的看看书,对于一些认为没啥用的知识点,也建议去仔细的看看,练练手,说不定什么时候就用到了,到时也好有针对性的去查,不至于盲目的按照自己的思路,重复 ...