今天我又想做一个小功能需要查询STEEM用户的钱包历史,结果又发现官方的API示例不够简单.挺麻烦的,查了半小时后没有得到自己想要的,于是果断直接爪取SteemIt线上的网页.在这里先感谢 SteemIt.com 不阻止PHP直接抓取.
首先我们先来看看效果吧:
curl -X POST -d "id=justyy" https://uploadbeta.com/api/steemit/transfer-history/
很快的,就能返回一串JSON字符串,取前面几行,大概是这样的结构:
[{"time":"8\/14\/2017, 6:37:15 PM",
"time_desc":"1 hour ago",
"transaction":"Claim rewards: 8.203 SBD and 6.842 STEEM POWER",
"memo":""},
{"time":"8\/14\/2017, 6:00:12 PM",
"time_desc":"2 hours ago",
"transaction":"Claim rewards: 0.052 STEEM POWER",
"memo":""},... ...
怎么样,够好用吧,你直接可以用银河系里最好用的PHP语言这样来获取:
$id = 'justyy';
$tx = json_decode(file_get_contents("https://uploadbeta.com/api/steemit/transfer-history/?id=" . $id), true);
foreach ($tx as $r) {
echo $r['time'];
echo $r['time_desc'];
echo $r['memo'];
echo $r['transaction'];
}
SteemIt API/transfer-history 服务器
和 SteemIt API/account 一样,一共有4个API服务器已经正常运行很多年.
- 美国东部 (East USA):https://helloacm.com/api/steemit/transfer-history/
- 美国西部 (West USA):https://steakovercooked.com/api/steemit/transfer-history/
- 日本东京 (Tokyo Japan):https://happyukgo.com/api/steemit/transfer-history/
- 英国伦敦 (London, UK):https://uploadbeta.com/api/steemit/transfer-history/
使用CloudFlare缓存服务器来提速
您需要使用 /api/steemit/transfer-history/?cached&id=justyy 的形式利用Cloudflare CDN节点来加速.
SteemIt API/transfer-history 原代码
很简单,通过 phpQuery 抓取
compress.zlib://https://steemit.com/@$id/transfers
因为 steemit.com 返回是gzip 压缩的,所以需要指定 compress.zlib://
PHP原代码如下:
// https://justyy.com/archives/5070
$id = $_GET['id'] ?? (($_POST['id']) ?? '');
require_once('phpQuery.php');
function getTransfer($id) {
$doc = phpQuery::newDocumentFile("compress.zlib://https://steemit.com/@$id/transfers");
$arr = array();
foreach(pq('tr.Trans') as $p) {
$tx = array();
$x = pq($p);
$tx['time'] = $x->find('td:first>span')->attr('title');
$tx['time_desc'] = trim(strip_tags($x->find('td:first')->html()));
$tx['transaction'] = trim(strip_tags($x->find('td:eq(1)')->html()));
$tx['memo'] = trim(strip_tags($x->find('td:eq(2)')->html()));
$arr[] = $tx;
}
return $arr;
}
$data = getTransfer($id);
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
die(json_encode($data));
就这样,接下来明天我会写些小程序,让你们瞧瞧,这样的调用方式是多么的方便和快捷!
英文: How to Get Transfer History of SteemIt Accounts via SteemIt API/transfer-history?
本文一共 275 个汉字, 你数一下对不对.上一篇: 第一次打肿脸充胖子 - 花了200STEEM租1万SP四周!
下一篇: 如何使用Steem API/transfer-history和IFTTT同步到Slack消息?
扫描二维码,分享本文到微信朋友圈