-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.php
449 lines (386 loc) · 12.5 KB
/
client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<?php
/**
* 饭否操作类
*
* @package Wang Haosen
* @author Wang Haosen
* @version 1.0
@writen at July 6, 2011
@说明 这个文件是为饭否写的一个PHP SDK
@希望能给后来开发的人带来方便 ^_^
@注意,这个文件使用时必须先引用同文件夹下的oauth.php 和 config.php
@PS:没事来http://pagewant.com坐一坐~
*/
class FFClient
{
/**
* 构造函数
* @param mixed $akey 饭否给你的 APP KEY (Consumer_Key )
* @param mixed $skey 饭否给你的 APP SECRET (Consumer_Secret_Key )
* @param mixed $accecss_token OAuth认证返回的token
* @param mixed $accecss_token_secret OAuth认证返回的token secret
*/
function __construct( $akey , $skey , $accecss_token , $accecss_token_secret )
{
$this->oauth = new OAuth( $akey , $skey , $accecss_token , $accecss_token_secret );
}
//////////////////////////////////////////消息相关////////////////////////////////////////////////////
/**
* 显示随便看看的消息
* count是信息条数
*/
function public_timeline( $count = 20 )
{
return $this->oauth->get('http://api.fanfou.com/statuses/public_timeline.json?count='.$count);
}
/**
* 显示来自用户和好友的消息
* page 是页数,以下都是,不再说明
*/
function friends_timeline($page = 1, $count = 20)
{
return $this->request_with_pager( 'http://api.fanfou.com/statuses/friends_timeline.json' , $page , $count );
}
/**
* 显示用户的消息
*/
function user_timeline($page = 1, $count = 60, $max_id = false, $since_id = false)
{
$param = array();
if ( $max_id )
$param['max_id'] = $max_id;
if ( $since_id )
$param['since_id'] = $since_id;
return $this->request_with_pager( 'http://api.fanfou.com/statuses/user_timeline.json' , $page , $count, $param );
}
function photo_timeline($page = 1, $count = 60, $max_id = false, $since_id = false)
{
$param = array();
if ( $max_id )
$param['max_id'] = $max_id;
if ( $since_id )
$param['since_id'] = $since_id;
return $this->request_with_pager( 'http://api.fanfou.com/photos/user_timeline.json' , $page , $count, $param );
}
function fav_timeline($page = 1, $count = 60, $max_id = false, $since_id = false)
{
$param = array();
if ( $max_id )
$param['max_id'] = $max_id;
if ( $since_id )
$param['since_id'] = $since_id;
return $this->request_with_pager( 'http://api.fanfou.com/favorites/id.json' , $page , $count, $param );
}
/**
* 显示指定消息 通过消息ID
*/
function show( $stauts_id )
{
return $this->oauth->get( 'http://api.fanfou.com/statuses/show/'.$stauts_id.'.json');
}
/**
* 显示发给当前用户的消息
*/
function replies( $page = 1, $count = 20, $max_id = false, $since_id = false )
{
$param = array();
if ( $max_id )
$param['max_id'] = $max_id;
if ( $since_id )
$param['since_id'] = $since_id;
return $this->request_with_pager( 'http://api.fanfou.com/statuses/replies.json' , $page , $count, $param );
}
/**
* 最新 @用户的
* @param int $page 返回结果的页序号。
* @param int $count 每次返回的最大记录数(即页面大小),不大于200,默认为20。
* @return array
*/
function mentions( $page = 1 , $count = 20, $since_id = false )
{
return $this->request_with_pager( 'http://api.fanfou.com/statuses/mentions.json' , $page , $count, $since_id );
}
/**
* 发表微博
* @access public
* @param mixed $text 要更新的微博信息。
* @return array
*/
function update( $text, $in_reply_to_status_id=false, $in_reply_to_user_id=false)
{
$param = array();
$param['status'] = $text;
if ($in_reply_to_status_id)
$param['in_reply_to_status_id'] = $in_reply_to_status_id;
if ($in_reply_to_user_id)
$param['in_reply_to_user_id'] = $in_reply_to_user_id;
return $this->oauth->post( 'http://api.fanfou.com/statuses/update.json' , $param );
}
/**
* 发表图片微博
* @param string $text 要更新的微博信息。
* @param string $pic_path 要发布的图片路径,支持url。[只支持png/jpg/gif三种格式,增加格式请修改get_image_mime方法]
* @return array
*/
function upload( $text , $pic_path )
{
$param = array();
$param['status'] = $text;
$param['photo'] = '@'.$pic_path;
return $this->oauth->post( 'http://api.fanfou.com/photos/upload.json' , $param , true );
}
/**
* 转发微博
* @param mixed $text 要更新的微博信息。
* @return array
*/
function repost( $text , $repost_status_id)
{
$param = array();
$param['status'] = $text;
$param['repost_status_id'] = $repost_status_id;
return $this->oauth->post( 'http://api.fanfou.com/statuses/update.json' , $param );
}
/**
* 删除微博
* @param mixed $sid 要删除的微博ID
*/
function destroy( $sid )
{
$param = array();
$param['id'] = $sid;
return $this->oauth->post( 'http://api.fanfou.com/statuses/destroy.json', $param );
}
//////////////////////////////////////用户相关////////////////////////////////////////////
function rate_limit_status()
{
return $this->oauth->get( 'http://api.fanfou.com/account/rate_limit_status.json' );
}
function update_profile( $loc=false, $desc=false )
{
$param = array();
if ($loc) $param['location'] = $loc;
if ($desc) $param['description'] = $desc;
return $this->oauth->post( 'http://api.fanfou.com/account/update_profile.json', $param );
}
function get_saved_search( $callback = false )
{
$p = array();
if( $callback )
$p['callback'] = $callback;
return $this->oauth->get( 'http://api.fanfou.com/saved_searches/list.json', $p);
}
function show_saved_search( $id )
{
$p = array();
$p['id'] = $id;
return $this->oauth->get( 'http://api.fanfou.com/saved_searches/show.json', $p);
}
function add_saved_search( $q )
{
$p = array();
$p['query'] = $q;
return $this->oauth->post( 'http://api.fanfou.com/saved_searches/create.json', $p);
}
function del_saved_search( $id )
{
$p = array();
$p['id'] = $id;
return $this->oauth->post( 'http://api.fanfou.com/saved_searches/destroy.json', $p);
}
function universal_search( $q, $count = 1, $page = 1, $since_id = false, $max_id = false, $mode = 'lite' )
{
$p = array();
if( $since_id )
$p['since_id'] = $since_id;
if( $max_id )
$p['max_id'] = $max_id;
$p['q'] = $q;
$p['count'] = $count;
$p['mode'] = $mode;
return $this->oauth->get( 'http://api.fanfou.com/search/public_timeline.json', $p);
}
/**
* 个人资料
* @param mixed $uid用户UI
*/
function show_user( $uid = false )
{
$p = array();
if($uid)
$p['id'] = $uid;
return $this->oauth->get( 'http://api.fanfou.com/users/show.json', $p);
}
/**
* 通过ID得到用户的好友列表
*/
function friends( $id )
{
$p = array(
'id' => $id
);
return $this->oauth-> get( 'http://api.fanfou.com/friends/ids.json' , $p );
}
/**
* 通过ID得到用户的粉丝列表
*/
function followers( $id )
{
$p = array(
'id' => $id
);
return $this->request_with_uid( 'http://api.fanfou.com/followers/ids.json' , $p );
}
/**
* 关注一个用户
*/
function follow( $uid )
{
return $this->oauth->post( 'http://api.fanfou.com/friendships/create/'.$uid.'.json' );
}
/**
* 取消关注某用户
*/
function unfollow( $uid )
{
return $this->oauth->post( 'http://api.fanfou.com/friendships/destroy/'.$uid.'.json');
}
/**
* 判断好友关系是否存在
*/
function is_followed( $uid_a, $uid_b )
{
$param = array(
'user_a' => $uid_a,
'user_b' => $uid_b
);
return $this->oauth->get( 'http://api.fanfou.com/friendships/exists.json' , $param );
}
/**
* 获取私信列表
* @param int $page 页码
* @param int $count 每次返回的最大记录数,最多返回200条,默认20。
* @return array
*/
function list_dm( $page = 1 , $count = 60 , $since_id = false )
{
$param = array();
$param['page'] = $page;
$param['count'] = $count;
$param['since_id'] = $since_id;
$param['mode'] = 'lite';
return $this->request_with_pager( 'http://api.fanfou.com/direct_messages/inbox.json' , $param );
}
/**
* 发送的私信列表
* @param int $page 页码
* @param int $count 每次返回的最大记录数,最多返回200条,默认20。
* @return array
*/
function list_dm_sent( $page = 1 , $count = 20 )
{
return $this->request_with_pager( 'http://api.fanfou.com/direct_messages/sent.json' , $page , $count );
}
/**
* 发送私信
* @param mixed $uid_or_name UID或微博昵称
* @param mixed $text 要发生的消息内容,文本大小必须小于300个汉字。
* @return array
*/
function send_dm( $uid , $text , $in_reply_to_id = false )
{
$param = array();
$param['user'] = $uid;
$param['text'] = $text;
$param['mode'] = 'lite';
if ( $in_reply_to_id )
$param['in_reply_to_id'] = $in_reply_to_id;
return $this->oauth->post( 'http://api.fanfou.com/direct_messages/new.json' , $param );
}
/**
* 删除一条私信
* @param mixed $did 要删除的私信主键ID
* @return array
*/
function delete_dm( $did )
{
$param = array();
$param['id'] = $did;
return $this->oauth->post( 'http://api.fanfou.com/direct_messages/destroy.json', $param );
}
/**
* 返回用户的发布的最近20条收藏信息,和用户收藏页面返回内容是一致的。
* @param bool $page 返回结果的页序号。
* @return array
*/
function get_favorites( $page = 1 , $count = 20 )
{
$param = array();
if( $page ) $param['page'] = $page;
if( $count ) $param['count'] = $count;
return $this->oauth->get( ' http://api.fanfou.com/favorites.json' , $param );
}
/**
* 收藏一条微博信息
* @param mixed $sid 收藏的微博id
* @return array
*/
function add_to_favorites( $sid )
{
$param = array();
$param['id'] = $sid;
return $this->oauth->post( 'http://api.fanfou.com/favorites/create/'. $sid .'.json' );
}
/**
* 删除微博收藏。
* @param mixed $sid 要删除的收藏微博信息ID.
* @return array
*/
function remove_from_favorites( $sid )
{
return $this->oauth->post( 'http://api.fanfou.com/favorites/destroy/' . $sid . '.json' );
}
function verify_credentials()
{
return $this->oauth->get( 'http://api.fanfou.com/account/verify_credentials.json' );
}
// =========================================
/**
* @ignore
*/
protected function request_with_pager( $url , $page = false , $count = false , $max_id = false , $since_id = false )
{
$param = array();
if( $page ) $param['page'] = $page;
if( $count ) $param['count'] = $count;
if( $max_id ) $param['max_id'] = $max_id;
if( $since_id ) $param['since_id'] = $since_id;
return $this->oauth->get($url , $param );
}
/**
* @ignore
*/
protected function request_with_uid( $url , $uid_or_name , $page = false , $count = false , $cursor = false , $post = false )
{
$param = array();
if( $page ) $param['page'] = $page;
if( $count ) $param['count'] = $count;
if( $cursor )$param['cursor'] = $cursor;
if( $post ) $method = 'post';
else $method = 'get';
if( is_numeric( $uid_or_name ) )
{
$param['user_id'] = $uid_or_name;
return $this->oauth->$method($url , $param );
}elseif( $uid_or_name !== null )
{
$param['screen_name'] = $uid_or_name;
return $this->oauth->$method($url , $param );
}
else
{
return $this->oauth->$method($url , $param );
}
}
}
?>