Notice: My personal stance on AI generated artwork. Retweet and share if you agree. Let us discuss, and not immediately scream bloody murder.

Now Viewing: API response format
Keep it civil, do not flame or bait other users. If you notice anything illegal or inappropriate being discussed, contact an administrator or moderator.

impaxel - Group: Member - Total Posts: 2
user_avatar
API response format
Posted on: 02/26/16 12:16PM

How can I get json data? According to gelbooru.com/index.php?page=tracker&s=view&id=284 posts api supporting json.



Jerl - Group: The Real Administrator - Total Posts: 6721
user_avatar
Posted on: 02/26/16 01:10PM

Add &json=1 to the request.



impaxel - Group: Member - Total Posts: 2
user_avatar
Posted on: 06/07/16 06:04AM

Is there a way to get a random post through API?



Jerl - Group: The Real Administrator - Total Posts: 6721
user_avatar
Posted on: 06/07/16 06:46AM

Not directly. The recommended indirect method is:

1. Load the API search normally, with &limit=1 added to the request to limit it to return 1 item. (The limit is to save bandwidth, and at this point not strictly necessary.)

2. Get the number of results from the count in the API response.

3. Generate a random number between 1 and that number inclusive.

4. Load the API search with &limit=1&offset={N}, where {N} is the number you generated. The limit will limit the number of results to 1, and offset will load the N'th page of results. Since each page is 1 result long, you will get the N'th result for the search, which will be random since you generated N randomly.

You will now have one random post from any possible tag search, including the main post listing.



add_replyAdd Reply


1