SteemJS Post not appearing under new fix

in #steemdev7 years ago (edited)

Problem

If you are starting with SteemJS and you are following the tutorial on this website https://developers.steem.io/#quickstartexample to post an article with SteemJS, you will find that your post will not occur under the "new" section of the first tag, even though the first tag exists when you view the article.

Solution

The code for posting looks like this:

function postArticle()
{
  steem.broadcast.comment(
   steem.api.setOptions({ url: 'https://api.steemit.com'});
    document.getElementById('postingKey').value, // posting wif
    '', // author, leave blank for new post
    'steemit', // first tag
    document.getElementById('username').value, // username
    'name-of-my-test-article-post', // permlink
    document.getElementById('title').value, // Title
    document.getElementById('article').value, // Body of post
    // json metadata (additional tags, app name, etc)
    { tags: ['secondtag'], app: 'steemjs-test!' },
    function (err, result) {
      if (err)
        alert('Failure! ' + err);
      else
        alert('Success!');
    }
  );
}



Take note of the line steem.api.setOptions({ url: 'https://api.steemit.com'});which does not exist in the example code on the website. This is necessary for the code to work as discuss in my previous article on SteemJS.

Now we will encounter our next problem. If you follow the instructions for this code, you will see that it says you put the first tag in line 7, and any additional tags in line 13. However, if you write a post and post it with this exact same code, you will discover that if you go to the "new" section and click on the "steemit" tag, you will not see your article.

This is because you also need to put your first tag "steemit" inside the json metadata (line 13) { tags: ['secondtag'], app: 'steemjs-test!' },. When you click on new, steemit looks inside the json meta tag of each article and looks for the that specific tag. If you don't put your first tag inside json metadata, Steemit will not be able to find your article and put it inside "new". So you should change line 13 to { tags: ['steemit','secondtag','thirdtag','fourthtag','fifthtag'] }. You can delete the app:'steemjs-test!' part and the program will still work.

So the updated code now looks like this, if you want your article to appear in the "new" section of the first tag.

function postArticle()
{
  steem.broadcast.comment(
   steem.api.setOptions({ url: 'https://api.steemit.com'});
    document.getElementById('postingKey').value, // posting wif
    '', // author, leave blank for new post
    'steemit', // first tag
    document.getElementById('username').value, // username
    'name-of-my-test-article-post', // permlink
    document.getElementById('title').value, // Title
    document.getElementById('article').value, // Body of post
    // json metadata (additional tags, app name, etc)
    { tags: ['steemit','secondtag','thirdtag','fourthtag','fifthtag'] },
    function (err, result) {
      if (err)
        alert('Failure! ' + err);
      else
        alert('Success!');
    }
  );
}

I hope this helps you fix the problem which puzzled me for a while.


修復用SteemJS發的文章不在'new'頁面的問題

如果你用Steemit開發人網站上的SteemJS範例來做一個發文章的app, 你可能會發現你發的文章沒有出現在第一個標籤的'new'的頁面,雖然在文章裡有顯示第一個標籤。主要是因為,官方的範例中,說第一個標籤只要放在第七行,而第13行jsoon metadata裡放的是剩下的標籤。

如果你完全照範例發,你就會發現,你到第一個steemit標籤下的new頁面,會找不到你的文章。因為你在按了new以後,steemit會把所有文章裡面找出json metadata有這個標籤的文章然後列出來。如果你的json metadata裡沒有這個標籤,則不會出現在new.

所以要改的基本上就是在第十三行的tags方括号裡面,也要寫第一個標籤。這樣你的文章就會出現在這個標籤的new頁面了。

Sort:  

Sos, this article is full of computer-language, I wish I can understand it, but I can't :( Btw, my upvote doesn't worth anything 'cuz I'm a newbie here, but I'm posting this comment as a support. If you want, you can check my introduction post and leave me some feedback. And yeah, I'm 17 :) PEACE!

i dont know Steemjs but is interesting, probably investigates about that :)

this is great , i checked out the link on it and i saw up to 5 users there , when i started earlier last year i encountered some prob;ems like this , up till now i stikll have some minor issues but i know am gonna be better someday

Coin Marketplace

STEEM 0.19
TRX 0.14
JST 0.029
BTC 64063.06
ETH 3144.15
USDT 1.00
SBD 2.55