aboutsummaryrefslogtreecommitdiff
path: root/lib/TwitterClient.php
diff options
context:
space:
mode:
authorGravatar Dag <me@dvikan.no> 2023-06-27 16:11:41 +0200
committerGravatar GitHub <noreply@github.com> 2023-06-27 16:11:41 +0200
commit8eabdbe5f8b67d29bbbf7a3ae4f1089d9f66e9ad (patch)
tree6d51684503b3bb3ffffa11064edaba5d3877a863 /lib/TwitterClient.php
parentbd6f56383c101292873aa0d43c8742b885479bb0 (diff)
downloadrss-bridge-8eabdbe5f8b67d29bbbf7a3ae4f1089d9f66e9ad.tar.gz
rss-bridge-8eabdbe5f8b67d29bbbf7a3ae4f1089d9f66e9ad.tar.zst
rss-bridge-8eabdbe5f8b67d29bbbf7a3ae4f1089d9f66e9ad.zip
fix(Twitter): properly find time line entries when ordering is inconsistent (#3461)
Diffstat (limited to 'lib/TwitterClient.php')
-rw-r--r--lib/TwitterClient.php22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/TwitterClient.php b/lib/TwitterClient.php
index fa8d765f..605c27ff 100644
--- a/lib/TwitterClient.php
+++ b/lib/TwitterClient.php
@@ -48,17 +48,29 @@ class TwitterClient
if ($result->__typename === 'UserUnavailable') {
throw new \Exception('UserUnavailable');
}
- $instructionTypes = ['TimelineAddEntries', 'TimelineClearCache'];
+ $instructionTypes = [
+ 'TimelineAddEntries',
+ 'TimelineClearCache',
+ 'TimelinePinEntry', // unclear purpose, maybe pinned tweet?
+ ];
$instructions = $result->timeline_v2->timeline->instructions;
if (!isset($instructions[1])) {
throw new \Exception('The account exists but has not tweeted yet?');
}
- $instruction = $instructions[1];
- if ($instruction->type !== 'TimelineAddEntries') {
- throw new \Exception(sprintf('Unexpected instruction type: %s', $instruction->type));
+
+ $entries = null;
+ foreach ($instructions as $instruction) {
+ if ($instruction->type === 'TimelineAddEntries') {
+ $entries = $instruction->entries;
+ break;
+ }
}
+ if (!$entries) {
+ throw new \Exception(sprintf('Unable to find time line tweets in: %s', implode(',', array_column($instructions, 'type'))));
+ }
+
$tweets = [];
- foreach ($instruction->entries as $entry) {
+ foreach ($entries as $entry) {
if ($entry->content->entryType !== 'TimelineTimelineItem') {
continue;
}