腾讯微博json

php抓取与返回数据结构

php抓取
使用file_get_contents,代码:


这个$content就是包含微博信息的一个数组了,你可以用print_r来看看具体内容,这里简单表示下$content得内容结构:

Array
(
[data] => Array
(
[0] => Array
(
[content] => 微博广播内容
[count] => 0
[from] => 1
[fromarea] => QQ
[id] => 1234567890123
[image] => ,
[isvip] => 0
[name] => name
[nick] => nick
[pic] => http://mbloghead.store.qq.com/mbloghead/69b0fa641c7aca379594
[status] => 0
[timestamp] => 1312204492
[type] => 1
)
)
[fans] => Array
(
[0] => Array
(
[name] => adoing
[nick] => abc
[url] =>
)
 )
[info] => Array
(
[city] => 15
[conntry] => 1
[fansnum] => 54
[isidol] => 0
[location] => 火星
[name] => wapdevelop
[nick] => adoing
[province] => 34
[sex] => 1
[url] => http://mbloghead.store.qq.com/mbloghead/69b0fa641c7aca379594
[vip] => 0
 )
 [msg] => ok
 [ret] => 0
 [time] => 1312209021
)

其中的data是最基本的广播的结构,转播和对话还有个source字段,这里不再列出。有了这些资料,用php输出这些东西应该不成问题了。

Javascript抓取
因为已经引用了jQuery库,再加上javascript中ajax的跨域操作比较繁琐,这里直接使用了jQuery.getJSON方法,下面是抓取代码:

jQuery(document).ready(function($){
var jsonUrl="http://v.t.qq.com/output/json.php?type=1&name=hackgyj&sign=5a3d7ef58142cd19d06556b3553f9dc01ce38609"; //json
$.getJSON(jsonUrl+'?callback=?',weiboData=function(c){
//下面可以处理json数据了,c就是返回的json对象
});
});