[iOS微博项目 - 2.6] - 获取微博数据




/** 加载微博数据 */
- (void) loadWeiboData {
// 创建AFNetworking的http操作中管理器
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; // 设置参数
NSMutableDictionary *param = [NSMutableDictionary dictionary];
param[@"access_token"] = [HVWAccountInfoTool accountInfo].access_token; // 发送请求
[manager GET:@"https://api.weibo.com/2/statuses/home_timeline.json" parameters:param success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
HVWLog(@"获取微博数据成功-------%@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
HVWLog(@"获取微博数据失败------%@", error);
}];
}
statuses = [
{
rid = 0_0_2669621413509583897,
visible = {
type = 0,
list_id = 0
},
original_pic = http://ww1.sinaimg.cn/large/c3ad47bejw1eoygflrel2g201w034q34.gif,
mid = 3806890389487492,
source = <a href="http://app.weibo.com/t/feed/3j6BDx" rel="nofollow">孔明社交管理</a>,
truncated = 0,
reposts_count = 2,
bmiddle_pic = http://ww1.sinaimg.cn/bmiddle/c3ad47bejw1eoygflrel2g201w034q34.gif,
darwin_tags = [
],


//
// HVWUser.h
// HVWWeibo
//
// Created by hellovoidworld on 15/2/5.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import <Foundation/Foundation.h> @interface HVWUser : NSObject /** 友好显示名称 */
@property(nonatomic, copy) NSString *name; /** 用户头像地址(中图),50×50像素 */
@property(nonatomic, copy) NSString *profile_image_url; +(instancetype) userWithDict:(NSDictionary *) dict; @end
//
// HVWUser.m
// HVWWeibo
//
// Created by hellovoidworld on 15/2/5.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import "HVWUser.h" @implementation HVWUser +(instancetype) userWithDict:(NSDictionary *) dict {
HVWUser *user = [[self alloc] init]; user.name = dict[@"name"];
user.profile_image_url = dict[@"profile_image_url"]; return user;
} @end
//
// HVWStatus.h
// HVWWeibo
//
// Created by hellovoidworld on 15/2/5.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import <Foundation/Foundation.h>
#import "HVWUser.h" @interface HVWStatus : NSObject /** 微博信息内容 */
@property(nonatomic, copy) NSString *text; /** 微博作者的用户信息字段 详细 */
@property(nonatomic, strong) HVWUser *user; /** 微博配图地址数组,里面装载的时HVWPic模型 */
@property(nonatomic, strong) NSArray *pic_urls; + (instancetype) statusWithDict:(NSDictionary *) dict; @end
//
// HVWStatus.m
// HVWWeibo
//
// Created by hellovoidworld on 15/2/5.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import "HVWStatus.h"
#import "HVWUser.h" @implementation HVWStatus + (instancetype) statusWithDict:(NSDictionary *) dict {
HVWStatus *status = [[HVWStatus alloc] init]; status.text = dict[@"text"];
status.user = [HVWUser userWithDict:dict[@"user"]]; return status;
} @end
// HVWHomeViewController.m
/** 加载微博数据 */
- (void) loadWeiboData {
// 创建AFNetworking的http操作中管理器
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; // 设置参数
NSMutableDictionary *param = [NSMutableDictionary dictionary];
param[@"access_token"] = [HVWAccountInfoTool accountInfo].access_token; // 发送请求
[manager GET:@"https://api.weibo.com/2/statuses/home_timeline.json" parameters:param success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
// HVWLog(@"获取微博数据成功-------%@", responseObject); // 保存数据到内存
NSArray *dataArray = responseObject[@"statuses"]; for (NSDictionary *dict in dataArray) {
HVWStatus *status = [HVWStatus statusWithDict:dict];
[self.statuses addObject:status];
} // 刷新数据
[self.tableView reloadData]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
HVWLog(@"获取微博数据失败------%@", error);
}];
} - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"HomeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (nil == cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
} HVWStatus *status = self.statuses[indexPath.row];
HVWUser *user = status.user; // 加载内容
cell.textLabel.text = status.text;
// 作者
cell.detailTextLabel.text = user.name;
// 作者头像
NSString *imageUrlStr = user.profile_image_url;
[cell.imageView setImageWithURL:[NSURL URLWithString:imageUrlStr] placeholderImage:[UIImage imageWithNamed:@"avatar_default_small"]]; return cell;
}

//
// HVWUser.h
// HVWWeibo
//
// Created by hellovoidworld on 15/2/5.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import <Foundation/Foundation.h> @interface HVWUser : NSObject /** 友好显示名称 */
@property(nonatomic, copy) NSString *name; /** 用户头像地址(中图),50×50像素 */
@property(nonatomic, copy) NSString *profile_image_url; @end
//
// HVWStatus.h
// HVWWeibo
//
// Created by hellovoidworld on 15/2/5.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import <Foundation/Foundation.h>
#import "HVWUser.h" @interface HVWStatus : NSObject /** 微博信息内容 */
@property(nonatomic, copy) NSString *text; /** 微博作者的用户信息字段 详细 */
@property(nonatomic, strong) HVWUser *user; /** 微博配图地址数组,里面装载的时HVWPic模型 */
@property(nonatomic, strong) NSArray *pic_urls; @end
// HVWHomeViewController.m
/** 加载微博数据 */
- (void) loadWeiboData {
// 创建AFNetworking的http操作中管理器
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; // 设置参数
NSMutableDictionary *param = [NSMutableDictionary dictionary];
param[@"access_token"] = [HVWAccountInfoTool accountInfo].access_token; // 发送请求
[manager GET:@"https://api.weibo.com/2/statuses/home_timeline.json" parameters:param success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
// HVWLog(@"获取微博数据成功-------%@", responseObject); // 保存数据到内存
NSArray *dataArray = responseObject[@"statuses"]; // 使用MJExtension直接进行字典-模型转换
self.statuses = [HVWStatus objectArrayWithKeyValuesArray:dataArray]; // 刷新数据
[self.tableView reloadData]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
HVWLog(@"获取微博数据失败------%@", error);
}];
}


//
// HVWPic.h
// HVWWeibo
//
// Created by hellovoidworld on 15/2/5.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import <Foundation/Foundation.h> @interface HVWPic : NSObject /** 缩略图片地址,没有时不返回此字段 */
@property(nonatomic, copy) NSString *thumbnail_pic; @end

//
// HVWStatus.m
// HVWWeibo
//
// Created by hellovoidworld on 15/2/5.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import "HVWStatus.h"
#import "HVWPic.h" // 注意引入框架
#import "MJExtension.h" @implementation HVWStatus - (NSDictionary *)objectClassInArray {
// 返回一个字典,创建数组子元素和包装类的映射关系
return @{@"pic_urls": [HVWPic class]};
} @end

[iOS微博项目 - 2.6] - 获取微博数据的更多相关文章
- [iOS微博项目 - 3.6] - 获取未读消息
github: https://github.com/hellovoidworld/HVWWeibo A.获取登陆用户未读消息 1.需求 获取所有未读消息,包括新微博.私信.@.转发.关注等 把未 ...
- [iOS微博项目 - 3.2] - 发送微博
github: https://github.com/hellovoidworld/HVWWeibo A.使用微博API发送微博 1.需求 学习发送微博API 发送文字微博 发送带有图片的微博 ...
- [iOS微博项目 - 3.4] - 获取用户信息
github: https://github.com/hellovoidworld/HVWWeibo A.获取用户信息 1.需求 获取用户信息并储存 把用户昵称显示在“首页”界面导航栏的标题上 ...
- [iOS微博项目 - 3.1] - 发微博界面
github: https://github.com/hellovoidworld/HVWWeibo A.发微博界面:自定义UITextView 1.需求 用UITextView做一个编写微博的输 ...
- [iOS微博项目 - 4.0] - 自定义微博cell
github: https://github.com/hellovoidworld/HVWWeibo A.自定义微博cell基本结构 1.需求 创建自定义cell的雏形 cell包含:内容.工具条 内 ...
- 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.文字永远是一行,不 ...
- 项目中对获取的数据进行下载成Excel表格
//moment是操作日期的插件 //引入lodash是为了方便操作数据 //xlsx是获取表格的必须插件 import moment from 'moment'; import _ from ...
随机推荐
- HDU 2062 Subset sequence
我是把它当做一道数学题来做的. 这篇题解写的有点啰嗦,但是是我最原始的思维过程. 对于一个集合An= { 1, 2, …, n },在n比较小的情况下,在纸上按字典顺序把所有子集排列一下. 以n=3, ...
- jsp内置对象和el表达式
九个内置对象 *out jsp的输出流,用来向客户端响应 *page 当前jsp页面, 它的引用数据类型是Object,即真身中有如下代码 Object page=this; *config 它对应真 ...
- kdtree备份
库在这里 这个很好用. 例子: /*! gcc -Wall -g -o test test.c libkdtree.a */ #include <stdio.h> #include < ...
- 百度地图API开发指南
简介什么是百度地图API? 百度地图API是一套由JavaScript语言编写的应用程序接口,它能够帮助您在网站中构建功能丰富.交互性强的地图应用.百度地图API包含了构建地图基本功能的各种接口,提供 ...
- RandomAccessFile、FileChannel、MappedByteBuffer读写文件
s package com.nio; import java.io.Closeable; import java.io.FileNotFoundException; import java.io.IO ...
- 【剑指offer 面试题38】数字在排序数组中出现的次数
思路: 利用二分查找,分别查找待统计数字的头和尾的下标,最后做差加一即为结果. C++: #include <iostream> #include <vector> using ...
- FreeMarker笔记 第二章 数值和类型
2.1 基本内容 2.1.1 简介 2.1.2 什么是数值 和程序语言中的数值类型是相似的. 2.1.3 什么是类型? 2.1.4 数据模型是哈希表 2.2 类型 2.2.1 简介 2.2.2 标量 ...
- bzoj 2038 [2009国家集训队]小Z的袜子(hose)(莫队算法)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2038 [题意] 给定一个有颜色的序列,回答若干个询问:区间内任选两个颜色相同的概率. ...
- WebGoat学习——跨站脚本攻击(Cross‐Site Scripting (XSS))
跨站脚本攻击(Cross‐Site Scripting (XSS)) XSS(Cross Site Script)跨站脚本攻击.是指攻击者向被攻击Web 页面里插入恶意html代码,当用户浏览该页之时 ...
- Maven安装与全局profile配置
Maven 3.2 需要 JDK 1.6, Maven 3.0/3.1 需要 JDK 1.5 · 解压. · 环境变量 M2_HOME · M2 = %M2_HOME%\bin 同时也添加到PATH ...