social-protocols / jabble

Collaborative Fact Checking
https://jabble.xyz
13 stars 0 forks source link

twitter integration #208

Closed johnwarden closed 1 month ago

johnwarden commented 1 month ago

This branch adds a page for submitting Tweets as a separate route: /submit-tweet

This page integrates with Twitter in two ways:

  1. Embedded tweet previews using the oEmbed API

Twitter provides the oEmbed API for embedding tweets in pages: https://developer.x.com/en/docs/x-for-websites/oembed-api#item1

This API lets you embed a Tweet on a page but it does not pull the full text (past the "Read more..." link)

The /submit-tweet page looks at the URL as the user types, and if it recognizes a valid tweet URL, it will call the oEmbed API and display the tweet preview.

Because of CORS issues, I had to create an API endpoint /oembed to proxy the Twitter oEmbed API.

The form won't let the user submit the artifact unless the /oembed call succeeds, ensuring that the tweet actually exists.

  1. Fetching full tweet text using the GraphQL API

Users only have to enter the tweet URL, and not the text.

I modified the claim-service to behave differently for tweet URLs. It it recognizes a twitter URL, it uses the GraphQL API to fetch the full tweet text, and uses this instead of quoteContent (which will be empty if it comes from the /submit-tweet page).

I used a package called https://github.com/the-convocation/twitter-scraper for this. However this package is not published to NPM, and it involves a build step so it can't be npm installed from the github URL. So I forked it and committed the built source, so that it could be directly npm installed.

Todos: