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.
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:
Either we should:
Integrate the tweet submission page with the artefact submission page. Perhaps the user enters the URL first, and if it is not a Twitter URL the textarea where the user manually enters the quote appears.
This branch adds a page for submitting Tweets as a separate route: /submit-tweet
This page integrates with Twitter in two ways:
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.
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:
Either we should:
Integrate the tweet submission page with the artefact submission page. Perhaps the user enters the URL first, and if it is not a Twitter URL the textarea where the user manually enters the quote appears.
Only allow tweet (and other known) URLs for now?
Consistency with artefact-submission