Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API call only returns 10 results #6

Closed
Ryan-Gordon opened this issue Aug 10, 2016 · 10 comments
Closed

API call only returns 10 results #6

Ryan-Gordon opened this issue Aug 10, 2016 · 10 comments

Comments

@Ryan-Gordon
Copy link

When calling the API via http only 10 post objects are returned. Sequential calls to the api via http also return the same results from the previous call

@bonustrack
Copy link
Contributor

Can you show me your code? I would like to reproduce the issue. Thank you.

@Ryan-Gordon
Copy link
Author

Ryan-Gordon commented Aug 11, 2016

Sure thing :) I'm not sure if you want the full code but here is the relevant code. I should point out I am using the steem rest api link atm.

When calling the load method, the api is called however the same data as before is returned a second time.
HTTP request as a service

`load() {

        // don't have the data yet
        console.log("Starting Promise");
        return new Promise(resolve => {
          // We're using Angular HTTP provider to request the data,
          // then on the response, it'll map the JSON data to a parsed JS object.
          // Next, we process the data and resolve the promise with the new data.
          this.http.get('https://api.steemjs.com/getState?path=/trending&scope=content')
            .map(res => res.json())
            .subscribe(data => {
              // we've got back the raw data, now generate the core schedule data
              // and save the data for later reference


              this.data = data;
              console.log("Currently inside the service ");
              resolve(this.data);
              console.log("Leaving the service \n\n ");
            });
        });

Function where I am calling the Http request

loadnewPosts(){
    this.newPosts.load()
      .then(data => {
        this.posts = data;
        //console.log(JSON.stringify(this.posts));
        this.arrayIndex = 0;
        for (var key in data) {

          console.log(key + " -> " + data[key]);
          console.log("Post: Author -> " + data[key].author);
          console.log("Post: title -> " + JSON.stringify(data[key].root_title));
          console.log("Post: Votes -> " + JSON.stringify(data[key].net_votes));
          console.log("Post: url -> " + JSON.stringify(data[key].url));
          console.log("Post: url -> "+JSON.stringify(data[key].json_metadata));
          console.log("Post: url -> "+JSON.stringify(data[key].total_pending_payout_value));


@KrNel
Copy link

KrNel commented Nov 7, 2016

Yeah, I only get 20 results on a getState for "created" as the path: getState?path=/created

How do we get the next 20?

@p0o
Copy link
Contributor

p0o commented Nov 7, 2016

If you want to load feed content getDiscussionBy.. endpoints are more reliable.
For example:

steem.api.getDiscussionsByCreated(query,(err, result) => {
    console.log(err, result);
});

or in Promise form:

steem.api.getDiscussionsByCreatedAsync(query).then((result) => {
    console.log(result);
});

Which in query you can pass an object with these parameters:

{
  limit: 10,
  start_author: lastAuthorYouLoaded,
  start_permlink: lastPermlinkYouLoaded
}

By omitting start_author and start_permlink you will get the first 10 results.

@KrNel
Copy link

KrNel commented Nov 7, 2016

Holy crap! Thank you! Is this anywhere in the master doc, int he examples, anywhere? I don't think I would have figured it out without you. Can you tell how you knew to do this? I'm really looking for where this is setup in the actual code.

I'm trying to go through the github files and find where these methods exist. Downloading all the file, then searching, for example, the method 'getState', I can't find it declared as a function in any file. I wanted to see what the methods are, what they are coded, and what the possible parameters are and then I could see how to call and pass vars to them.

Any help you can offer to get me to be able to find these methods and see how to manipulate them myself, would be greatly appreciated. Thanks for the help so far. Peace.

@p0o
Copy link
Contributor

p0o commented Nov 7, 2016

@KrNel Your welcome. These codes are not all included in this package. These are originated from the main steem API. There is a not very known doc here which might be helpful. However, right now I mostly figure out these things by monitoring web socket connections in steemit.com.

Also this file contains the functions we are supporting in this package. A generator function is creating methods from that file so if you're looking for getState you should search for get_state

@KrNel
Copy link

KrNel commented Nov 7, 2016

Thanks @p0o I knew about that last method file, but didn't know how to add the limit. I was previously using the https api, and even tried a URL call: https://api.steemjs.com/getState?path=/created&limit=10 but that didn't work hehehe. Thanks for the help.

@KrNel
Copy link

KrNel commented Nov 7, 2016

Does the query have any doc for it?

{
limit: 10,
start_author: lastAuthorYouLoaded,
start_permlink: lastPermlinkYouLoaded
}

Are there other params for query? I'm looking to only get certain fields, like author or title for instance (save bandwidth if possible...).

The page you linked to for the steem api only says:

get_discussions_by_created
params: tag(string), limit(integer)

But you also provided two other params. So what are the params?

Hopefully you can let me know of any others. Thanks.

@p0o
Copy link
Contributor

p0o commented Nov 7, 2016

@KrNel AFAIK there are not any other params for this context.

@KrNel
Copy link

KrNel commented Nov 8, 2016

@p0o

Ah well, thanks for the help. Peace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants