Lambs
February 26, 2022, 3:21pm
1
I am performing the query to get data from the helix api but I need to use the cursor with the migration and I can only perform the first query.
Is it necessary to make a loop to make use of the cursor? Could you provide me with a code using the cursor to see multiple pagination.
I’m still on kraken until I understand how to make cursor queries work on multiple pages, how long will I be available to use the kraken API?
You do not generate the cursor
The cursor is returned on the request you just made.
So, for example, you make a call to Get Streams
Which in the example returns
GET https://api.twitch.tv/helix/streams
"pagination": {
"cursor": "eyJiIjp7IkN1cnNvciI6ImV5SnpJam8zT0RNMk5TNDBORFF4TlRjMU1UY3hOU3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In0sImEiOnsiQ3Vyc29yIjoiZXlKeklqb3hOVGs0TkM0MU56RXhNekExTVRZNU1ESXNJbVFpT21aaGJITmxMQ0owSWpwMGNuVmxmUT09In19"
}
So to get the next page you then call
https://api.twitch.tv/helix/streams?after=eyJiIjp7IkN1cnNvciI6ImV5SnpJam8zT0RNMk5TNDBORFF4TlRjMU1UY3hOU3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In0sImEiOnsiQ3Vyc29yIjoiZXlKeklqb3hOVGs0TkM0MU56RXhNekExTVRZNU1ESXNJbVFpT21aaGJITmxMQ0owSWpwMGNuVmxmUT09In19
February 28th 7PM UTC
Yes you get a page of data. If it has a cursor you know you have another page to load
After making an axios call, extract the cursor and call the API again.
Lambs
February 26, 2022, 8:10pm
3
I manage to do the query and get the data from the stream in the case of your example and I get the cursor, the problem is that from there I don’t know how I can work with the cursor to get new paginations
{
id: '44820029260',
user_id: '34711476',
user_login: 'jesusavgn',
user_name: 'JesusAVGN',
game_id: '515214',
game_name: 'Politics',
type: 'live',
title: '!", ' !", https://t.me/jesusavgntwitch',
viewer_count: 23246,
started_at: '2022-02-26T19:32:50Z',
language: 'ru',
thumbnail_url: 'https://static-cdn.jtvnw.net/previews-ttv/live_user_jesusavgn-{width}x{height}.jpg',
tag_ids: [Array],
is_mature: false
}
],
pagination: {
cursor: 'eyJiIjp7IkN1cnNvciI6ImV5SnpJam95TkRJM05qRXVORFExTnpRMk5EWTJPRGNzSW1RaU9tWmhiSE5sTENKMElqcDBjblZsZlE9PSJ9LCJhIjp7IkN1cnNvciI6ImV5SnpJam95TXpJME5pNDRNRFUxTkRBeU16QTJNU3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In19'
}
}
axios.get(`https://api.twitch.tv/helix/streams/?first=20&after=${cursor}`,options);
cursor = get.data.pagination.cursor;
eyJiIjp7IkN1cnNvciI6ImV5SnpJam95TXpVeE1qQXVORFExTnpRMk5EWTJPRGNzSW1RaU9tWmhiSE5sTENKMElqcDBjblZsZlE9PSJ9LCJhIjp7IkN1cnNvciI6ImV5SnpJam95TXpjMk9TNHlOekV6TWpBeU16SXdPQ3dpWkNJNlptRnNjMlVzSW5RaU9uUnlkV1Y5In19
I’m trying to save the cursor value and use it in the following query but I’m not doing it right. If you can provide me with a code that is making use of the cursor and making the query so I can see how it is done, I would appreciate it.
I only manage to make it functional by manually making the call
Here is an example that users vanilla JS Fetch
console.log(err);
document.getElementById('loading').textContent = 'Something went wrong';
});
}
// max number of pages to stop
// you don't want to go too deep
// as in the first 20/30/50 pages you'll collect MOST of the statistically significant channels
// to get an approximation of the category
var limit = 50;
function fetchStreams(game_id, page, after, tot) {
page = page ? page : 0;
document.getElementById('loader_' + game_id).textContent = 'Loading Page: ' + page + ' Current ' + tot;
fetch(
'https://api.twitch.tv/helix/streams?first=100&game_id=' + game_id + (after ? '&after=' + after : ''),
{
"headers": {
"Client-ID": client_id,
"Authorization": "Bearer " + access_token
}
}
Lambs
February 26, 2022, 8:31pm
5
So more or less I have the code what is complicated for me is to make the loop and I do not understand much that code calls the function again to get the cursor but I do not fully understand
This sounds like a “I don’t know javascript” problem than an API problem.
I don’t know what you code does in order to debug your code.
So all I can do is point you to the example of how I do it.
Lambs
February 26, 2022, 8:49pm
7
I have already seen the problem, it was not interpreting the cursor variable correctly. I was only seeing the preview of your code and I didn’t know how it was working.
Query constraints increased in helix?
I’m not sure what you are asking here.
To paginate an endpoint you load page 1
Which returns the cursor for page 2
You cannot jump straight to page 4.