Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const BATCH_SIZE = 100;
- async function getComments(requestData, searchLimit) {
- const comments = [];
- // copy request data in order to doesn't modify original request data if it doesn't contain nested objects
- const requestData = { ... requestData };
- let isDone = false;
- do {
- const commentsResponse = await gapi.client.youtube.commentThreads.list(requestData);
- const retrievedComments = response.result.items;
- if(searchLimit <= BATCH_SIZE) {
- comments.push(retrievedComments.slice(0, searchLimit));
- isDone = true;
- } else {
- comments.push(retrievedComments);
- if(response.result.nextPageToken != undefined) {
- requestData.pageToken = response.result.nextPageToken;
- } else {
- isDone = true;
- }
- }
- searchLimit -= BATCH_SIZE;
- } while(isDone)
- return comments;
- }
- ### Usage
- async function run() {
- // я не представляю что там у тебя за обработка ошибок в SearchExceptionLog, так что тут думай сам
- const comments = await getComments(yourRequestData, 8841)
- .catch((err) => {
- SearchExceptionLog(err);
- process.exit(1);
- })
- // я не предсталвляю что делает эта функция и асинхронная ли она, так что тут думай сам
- const search = SearchInList(comments);
- }
Add Comment
Please, Sign In to add comment