[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的下载地址 ...
随机推荐
- Excel文件操作方式比较
C++读取Excel的XLS文件的方法有很多,但是也许就是因为方法太多,大家在选择的时候会很疑惑. 由于前两天要做导表工具,比较了常用的方法,总结一下写个短文, 1.OLE的方式 这个大约是最常用的方 ...
- BZOJ 1935 园丁的烦恼
离线,BIT. #include<iostream> #include<cstdio> #include<cstring> #include<algorith ...
- Python [Leetcode 350]Intersection of Two Arrays II
题目描述: Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, ...
- 07day2
居然是动规专场.这样不好吧? 采药 [问题描述] 辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师.为此,他想拜附近最有威望的医师为师.医师为了判断他的资质,给他出了一个难题.医师把他带到 ...
- 【C#学习笔记】改变颜色
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 极大似然估计&最大后验概率估计
https://guangchun.wordpress.com/2011/10/13/ml-bayes-map/ http://www.mi.fu-berlin.de/wiki/pub/ABI/Gen ...
- UVa725 - Division
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; int ...
- AsyncTask类
1.定义 异步任务类,在类中实现异步操作,并提供回调方法反馈当前异步执行的程度,最后反馈 的结果提供给UI主线程. <1>Android线程 ...
- HttpWebRequest代理访问网站
private void button1_Click(object sender, EventArgs e) { string str ="http://www.7y8.com/V/ip.a ...
- 使用JQuery Mobile实现手机新闻浏览器
jQuery Mobile项目是jQuery项目下的在移动开发方面的又一力作,在本文中,笔者将带你一步步更深入学习使用jQuery Mobile框架去实现一个能在android手机上运行的新闻浏览器, ...