Suppose you need to do a copy & paste of a conversation you had on Twitter to send it by email. Unfortunately, it's very hard to copy & paste it in toto from either the app or the web. Twitter makes it as hard as possible to do so, especially if you wish the whole conversation.
Conversations are conveniently stored as JSON files, but... you need to get access to them. One possible way to do so is the following:
- Ask Twitter for a link to an archive of all your data to be downloaded (they'll take up to 24 hours to provide you with it)
- Make sure
jqis installed - "862741-8538292" represents a conversation between two Twitter IDs (
recipientId) - You may have to massage the first line of
direct-messages.jsso that it reads
{
"window.YTD.direct_messages.part0" : [
...
]}instead of
window.YTD.direct_messages.part0 = [
...
]Don't forget to add the extra } at the end!
5. Then run on the shell something like:
$ unzip twitter-YYYY-MMM-lots-of-characters.zip
$ cat twitter-YYYY-MMM-lots-of-characters/data/direct-messages.js | jq -r '."window.YTD.direct_messages.part0"[].dmConversation|select(.conversationId |contains("862741-8538292"))|.messages[].messageCreate|.recipientId + " (" + (.createdAt) + ") " + .text' > output.txt- Remember: everything will come out of order (last messages first)!
jqconveniently does the necessary conversion of embedded\ninto newlines; no need to worry about those.- Twitter uses ISO 8601 datetime strings, but with milliseconds, which sadly the macOS version doesn't like
- You may optionally use
sedto replace the Twitter ID by the user's name (if you know it), etc. etc. etc.