SteemIt API/transfer-history 最简单获取帐号钱包记录的API

SteemIt API/transfer-history is made available to public, free of charge, on four API servers world wide.

今天我又想做一个小功能需要查询STEEM用户的钱包历史,结果又发现官方的API示例不够简单。挺麻烦的,查了半小时后没有得到自己想要的,于是果断直接爪取SteemIt线上的网页。在这里先感谢 SteemIt.com 不阻止PHP直接抓取。

Let's have a quick look on how to use this API
首先我们先来看看效果吧:

curl -X POST -d "id=justyy" https://uploadbeta.com/api/steemit/transfer-history/

It will soon returns a JSON-encoded string, with a first few lines that look like this:
很快的,就能返回一串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":""},... ...

And, here is how you use it in your production code.
怎么样,够好用吧,你直接可以用银河系里最好用的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 服务器

Like the API/steemit/account API, Four servers can also be chosen depending on your locations:
SteemIt API/account 一样,一共有4个API服务器已经正常运行很多年。

Using CloudFlare CDN Edge Server 使用缓存服务器来提速

You could also use CloudFlare CDN Edge servers to speed up the API requests by caching it on the edge servers, you need to use it like this:

/api/steemit/transfer-history/?cached&id=justyy

您需要使用 /api/steemit/transfer-history/?cached&id=justyy 的形式利用CloudFlare CDN节点来加速。

How it works? 原理

The following shows how easy it is to grab the page directly using phpQuery.
很简单,通过 phpQuery 抓取

compress.zlib://https://steemit.com/@$id/transfers

因为 steemit.com 返回是gzip 压缩的,所以需要指定 compress.zlib://

原代码如下: Full PHP Source Code:

  $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));

I'll show you some simple applications tomorrow of using these APIs.
就这样,接下来明天我会写些小程序,让你们瞧瞧,这样的调用方式是多么的方便和快捷!

如何使用Steem API/transfer-history和IFTTT同步到Slack消息? How to Use Steem API/transfer-history and IFTTT to sync to Slack?

Originally published at https://steemit.com Thank you for reading my post, feel free to FOLLOW and Upvote @justyy which motivates me to create more quality posts.

原创首发于 https://steemit.com 非常感谢阅读, 欢迎FOLLOW和Upvote @justyy 能激励我创作更多更好的内容.

// 稍候同步到我的中文博客英文博客

近期热贴 Recent Popular Posts

H2
H3
H4
3 columns
2 columns
1 column
13 Comments