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

in #cn7 years ago (edited)

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

Sort:  

试了 webapi.steemdata.com 不好用。

太好了。。。
但這是要怎樣使用的呢?

请听下回分解。

汉字看不懂,直奔代码哈哈哈

这。。。。

早啊。。我的生物钟慢慢的又向西去了。。。

早啊。。你这生物钟得改。

我试过,失败了。。。

又学会了新知识!

不客气。其实这就是比收益还能让我开心的, 我写的文章确实能帮到别人,我就很开心。

@justyy got you a $1.59 @minnowbooster upgoat, nice!
@justyy got you a $1.59 @minnowbooster upgoat, nice! (Image: pixabay.com)


Want a boost? Click here to read more!

I have to say that the content of most of the posts in steemit are generally low quality.
I very much have the feeling people want to make quick money on this very platform and produce as much content as possible.
What would you say to this? And, how could this be increased within the steemit community?
I believe in Quality-Over-Quantity!
Greetings, @martinmusiol

Coin Marketplace

STEEM 0.24
TRX 0.25
JST 0.040
BTC 94247.78
ETH 3407.39
USDT 1.00
SBD 3.45