今天我又想做一个小功能需要查询STEEM用户的钱包历史,结果又发现官方的API示例不够简单.挺麻烦的,查了半小时后没有得到自己想要的,于是果断直接爪取SteemIt线上的网页.在这里先感谢 SteemIt.com 不阻止PHP直接抓取.
首先我们先来看看效果吧:
1 | curl -X POST -d "id=justyy" https://uploadbeta.com/api/steemit/transfer-history/ |
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语言这样来获取:
1 2 3 4 5 6 7 8 | $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']; } |
$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原代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // 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)); |
// 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?
强烈推荐
- 英国代购-畅购英伦
- TopCashBack 返现 (英国购物必备, 积少成多, 我2年来一共得了3000多英镑)
- Quidco 返现 (也是很不错的英国返现网站, 返现率高)
- 注册就送10美元, 免费使用2个月的 DigitalOcean 云主机(性价比超高, 每月只需5美元)
- 注册就送10美元, 免费使用4个月的 Vultr 云主机(性价比超高, 每月只需2.5美元)
- 注册就送10美元, 免费使用2个月的 阿里 云主机(性价比超高, 每月只需4.5美元)
- 注册就送20美元, 免费使用4个月的 Linode 云主机(性价比超高, 每月只需5美元) (折扣码: PodCastInit2022)
- PlusNet 英国光纤(超快, 超划算! 用户名 doctorlai)
- 刷了美国运通信用卡一年得到的积分 换了 485英镑
- 注册就送50英镑 – 英国最便宜最划算的电气提供商
- 能把比特币莱特币变现的银行卡! 不需要手续费就可以把虚拟货币法币兑换
微信公众号: 小赖子的英国生活和资讯 JustYYUK