diff --git a/app/Services/Social/BlueskyAnalytics.php b/app/Services/Social/BlueskyAnalytics.php index cdb309ff..70eb2960 100644 --- a/app/Services/Social/BlueskyAnalytics.php +++ b/app/Services/Social/BlueskyAnalytics.php @@ -20,13 +20,16 @@ public function fetchPostMetrics(PostPlatform $postPlatform): array return ['unsupported' => true, 'reason' => 'missing_post_id']; } - $service = data_get($account->meta, 'service', 'https://bsky.social'); $did = $account->platform_user_id; $atUri = "at://{$did}/app.bsky.feed.post/{$postPlatform->platform_post_id}"; - // Public AppView API: no auth required for reading post counts. + // Read counts (likes, reposts, replies, quotes) live on the AT + // Protocol AppView, not the PDS. The user's PDS requires Bearer auth + // for this endpoint; the public AppView does not. + $appView = (string) config('trypost.platforms.bluesky.public_appview'); + $response = $this->socialHttp() - ->get("{$service}/xrpc/app.bsky.feed.getPosts", [ + ->get("{$appView}/xrpc/app.bsky.feed.getPosts", [ 'uris' => [$atUri], ]); diff --git a/app/Services/Social/MastodonAnalytics.php b/app/Services/Social/MastodonAnalytics.php index 3b176913..a7348f1c 100644 --- a/app/Services/Social/MastodonAnalytics.php +++ b/app/Services/Social/MastodonAnalytics.php @@ -22,8 +22,10 @@ public function fetchPostMetrics(PostPlatform $postPlatform): array $instance = data_get($account->meta, 'instance', 'https://mastodon.social'); + // Public posts: no auth needed. Our token only requests write scopes + // (read:accounts + write:statuses + write:media), so attaching the + // Bearer would 403 with "outside the authorized scopes". $response = $this->socialHttp() - ->withToken($account->access_token) ->get("{$instance}/api/v1/statuses/{$postPlatform->platform_post_id}"); if ($response->failed()) { diff --git a/config/trypost.php b/config/trypost.php index df4ff9e2..c0606acd 100644 --- a/config/trypost.php +++ b/config/trypost.php @@ -87,6 +87,7 @@ ], 'bluesky' => [ 'enabled' => env('BLUESKY_ENABLED', true), + 'public_appview' => env('BLUESKY_PUBLIC_APPVIEW', 'https://public.api.bsky.app'), ], 'mastodon' => [ 'enabled' => env('MASTODON_ENABLED', true),