Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Nodejs, vue.js 中使用,所以,请自行安装所需环境。

cnpm install steem --save

//main.js
import steem from 'steem'

//设置steem节点,挂载到全局
steem.api.setOptions({ url: 'https://anyx.io' })
Vue.prototype.steem= steem

steem节点国内测试:

https://cn.steems.top //平均 = 256ms 194ms 203ms
https://steemd.privex.io //平均 = 269ms 308ms 309ms
https://steemd.minnowsupportproject.org //平均 = 282ms 281ms 279ms

https://api.steemjiang.com //平均 = 327ms 373ms
https://api.steems.top //平均 = 337ms 365ms
https://api.justyy.com //平均 = 317ms 372ms
https://api.steem.bts.tw //平均 = 321ms 333ms

https://steem.61bts.com //平均 = 36ms,前端无法使用
https://s2.61bts.com //平均 = 159ms,前端无法使用
https://steem.bts.tw //平均 = 169ms,前端无法使用
https://steem-api.urbanpedia.com //平均 = 174ms,前端无法使用
https://api.steemit.com //无法使用
https://api.steemitdev.com //无法使用

Loading...
Loading...
Loading...
Loading...
steem.broadcast.accountUpdate(wif, account, owner, active, posting, memoKey, jsonMetadata, function(err, result) {
  console.log(err, result)
})
Loading...
Loading...
Loading...
Loading...
Loading...

一般依据标签对文章进行分类。tags在json_metadata中,这是字符串,要先JSON.parse转成对象形式

getCategory() {
  let category_net = "songofera"
  for (let i = 0; i < 100; i++) {
      let data_str = this.posts[i].json_metadata
      let data_obj = JSON.parse(data_str)
      if(data_obj.tags.includes(category_net)) {
        this.afterposts.push(this.posts[i])
        console.log(898, this.posts[i])
      }
  }
}
steem.api.getTrendingTags('cn', 15, function(err, result) { 
  //获取在cn后的15个流行标签 ,留空表示从最热门的开始
  console.log(123, err, result)
})

post.json_metadata还可以按需求写入其它的数据,有点类似MongoDB。这样的话易于对文章进行过滤,也可保存一些特殊的数据。

json_metadata: "{"tags":["cn","network-institute","markdown","html"],"app":"steemit\/0.1","format":"markdown"}"
eg:
let jsonMetadata = {"tags": tags, "dapp": "moochain", "format": "markdown", "cover": hash, "text": text}
JSON.stringify(jsonMetadata)
steem.api.getContent(author, permlink, function(err, result) {
  console.log(err, result)
})
eg:
steem.api.getContent('lemooljiang', 'steemjs-41', function(err, result) {
  console.log(934,err, result)
})
Loading...

SteemJS中有些函数可以加上Async,以得到Promise的写法。比如:steem.api.getContentAsync

//获取某篇文章
steem.api.getContentAsync(author, permlink)

//获取一篇文章的回复
steem.api.getContentRepliesAsync(author, permlink)

//连续获取文章
steem.api.getDiscussionsByAuthorBeforeDateAsync(author, null, beforeDate, 5)
  .then(res=>{
    console.log(222, res)
  })

//获取作者的评论
let query = { limit : 10, start_author:'lemooljiang', "start_permlink": pPermLink}
comments = await this.steem.api.getDiscussionsByCommentsAsync(query)


//获取帐户历史
steem.api.getAccountHistoryAsync(account, from, limit)
  .then(res=>{
    console.log(122, res)}
  )

帐户数据几乎都在这里了,包括创建的时间,余额,点赞能量等等。

steem.api.getAccounts(['lemooljiang'], function(err, result) {
  console.log(789,err, result);
});
Loading...
let query = { limit : 5, start_author:'lemooljiang', start_permlink: ""}
  this.steem.api.getDiscussionsByComments(query, function(err, result) {
    console.log(265, err, result)
  })
Loading...
this.steem.api.getFollowers('lemooljiang', '', 'blog', 10, function(err, result) {
  console.log(111, err, result)
})
this.steem.api.getFollowing('lemooljiang', '', 'blog', 10, function(err, result) {
  console.log(222, err, result)
})
Loading...
steem.broadcast.vote(wif, voter, author, permlink, weight, function(err, result) {
  console.log(err, result)
})

//函数讲解
steem.broadcast.vote (
    wif,         //发帖密钥
    voter,       //点赞人
    author,      //作者
    permlink,    // URL地址
    weight       //点赞比重,100*100
)
eg:
steem.broadcast.vote(
  "5KRSmEMffffff",
  "lemooljiang",
  "starnote",
  '6ekczn-2019',
  10000,
  function(err, result) {
    console.log(8888, err, result)
  })
Loading...
acc = "starnote"
following = "lemooljiang"
key = "5Jmwkffffffffff"
json = JSON.stringify(
  ['follow', {
    follower: acc,
    following: following,
    what: ['blog']
  }])
this.steem.broadcast.customJson(key, [], [acc], 'follow', json, function(err, result) {
  console.log(111,err, result)
})
steem.api.streamTransactions("head", function(err, result) {
    if (result && !err) {
      console.log(result)
    }
})
eg: 实时获取作者的文章或评论
getData() {
  this.steem.api.streamTransactions("head", function (err, result) {
    if (err) {
      alert("网络有问题!请更换API节点!")
    }
    let txType = result.operations[0][0] //获取操作类别
    let txData = result.operations[0][1] //获取操作内容
    if (txType == "comment" & txData.author == "lemooljiang") {  //获取作者的文章或评论
      let commentBody = txData.body
      let permlink = txData.permlink
      console.log(12345,commentBody)
    }
  })
}
Loading...
Loading...
steem.api.getContentReplies(author, permlink, function(err, result) {
  console.log(err, result)
})
eg:
steem.api.getContentReplies('lemooljiang', 'steemjs-41', function(err, result) {
  console.log(err, result)
})
Loading...
Loading...

Congratulations @lemooljiang! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 6500 comments. Your next target is to reach 7000 comments.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

网页打不开,好得可以点赞。

来自于 [WhereIn Android] (http://www.wherein.io)

我用手机试了一下,确实很慢!github在国内估计又被墙了!

Loading...

可以获取用户的余额、代理和公钥等数据

async getStates(){
  let username = "timool"
  let s = await this.steem.api.getAccountsAsync([username])
  console.log(789, s[0].balance)
}
Loading...
Loading...