Skip to content

Commit

Permalink
#286: Restore CommentThreads nextPageToken
Browse files Browse the repository at this point in the history
Solving [the Stack Overflow question 78877647](https://stackoverflow.com/q/78877647).
  • Loading branch information
Benjamin-Loison committed Aug 16, 2024
1 parent 79b1205 commit 38a3d80
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions commentThreads.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ function getAPI($videoId, $commentId, $order, $continuationToken, $simulatedCont
];
$answerItems[$properties['toolbarStateKey']] = $answerItem;
}
foreach ($result['onResponseReceivedEndpoints'][1]['reloadContinuationItemsCommand']['continuationItems'] as $item) {
$continuationItems = $result['onResponseReceivedEndpoints'][1]['reloadContinuationItemsCommand']['continuationItems'];
foreach ($continuationItems as $item) {
$commentThreadRenderer = $item['commentThreadRenderer'];
$toolbarStateKey = $commentThreadRenderer['commentViewModel']['commentViewModel']['toolbarStateKey'];
// How to avoid repeating path?
Expand All @@ -165,9 +166,12 @@ function getAPI($videoId, $commentId, $order, $continuationToken, $simulatedCont
if (doesPathExist($commentThreadRenderer, 'commentViewModel/commentViewModel/pinnedText')) {
$answerItems[$toolbarStateKey]['snippet']['topLevelComment']['snippet']['isPinned'] = true;
}
$answerItems[$toolbarStateKey]['snippet']['topLevelComment']['snippet']['nextPageToken'] = $commentThreadRenderer['replies']['commentRepliesRenderer']['contents'][0]['continuationItemRenderer']['continuationEndpoint']['continuationCommand']['token'];
if ($toolbarStateKey !== null) {
$answerItems[$toolbarStateKey]['snippet']['topLevelComment']['snippet']['nextPageToken'] = $commentThreadRenderer['replies']['commentRepliesRenderer']['contents'][0]['continuationItemRenderer']['continuationEndpoint']['continuationCommand']['token'];
}
}
$answerItems = array_values($answerItems);
$nextContinuationToken = $continuationItems[20]['continuationItemRenderer']['continuationEndpoint']['continuationCommand']['token'];

$answer = [
'kind' => 'youtube#comment' . ($isTopLevelComment ? 'Thread' : '') . 'ListResponse',
Expand Down

0 comments on commit 38a3d80

Please sign in to comment.