File size: 957 Bytes
9a43362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
 * Threads Scraper
 * Uses Apify Instagram Scraper (Threads is part of Meta)
 */

import { runApifyActor, ACTOR_IDS, type ScrapingResult } from './apify';
import { extractPostId } from './detector';

/**
 * Scrape Threads post by URL
 */
export async function scrapeThreads(url: string): Promise<ScrapingResult> {
  try {
    const postId = extractPostId(url);
    if (!postId) {
      return {
        success: false,
        error: 'Could not extract post ID from Threads URL',
      };
    }

    // Threads posts can be accessed via Instagram's API structure
    const result = await runApifyActor(ACTOR_IDS.threads, {
      direct_urls: [url],
      results_limit: 1,
    });

    return {
      ...result,
      title: 'Threads Post',
    };
  } catch (error) {
    console.error('[threads scraper] failed:', error);
    return {
      success: false,
      error: error instanceof Error ? error.message : 'Failed to scrape Threads',
    };
  }
}