Skip to content

Instantly share code, notes, and snippets.

@twilight-sparkle-irl
Last active September 14, 2022 04:17
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save twilight-sparkle-irl/6040275212f8822e48ef535459c97d44 to your computer and use it in GitHub Desktop.
Save twilight-sparkle-irl/6040275212f8822e48ef535459c97d44 to your computer and use it in GitHub Desktop.
pin retweets on twitter ----> ----> !! YOU NEED TO BE ON THE OLD LAYOUT, GET GoodTwitter !! <---- <----
$(document).ajaxComplete((e, x, o) => {
if (o.url == "https://api.twitter.com/1.1/statuses/retweet.json") {
tweet_id = JSON.parse(x.responseText)['id_str'];
auth_token = JSON.parse(document.querySelector('#init-data').value)['formAuthenticityToken'];
fetch("https://twitter.com/i/tweet/pin", {
body: `authenticity_token=${auth_token}&id=${tweet_id}`,
method: "POST",
headers: {
Accept: "application/json, text/javascript, */*; q=0.01",
"Cache-Control": "no-cache",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
"X-Twitter-Active-User": "yes"
}
}).then(res => res.json()).then(res => $(document).trigger('uiShowError', res))
}
})
// paste this into javascript console on a twitter permalink status page (https://twitter.com/[user]/status/[id])
// this will make any tweet you retweet on that page also pin itself to your profile
// this is very laggy bc jquery sucks
// so i recommend opening your tweet in a new tab, pasting the code, retweeting, and then closing the tab
// also this only works on old twitter, not nu PWA twitter
// enjoi
// oh also
// this works because when you retweet a tweet, you get a tweet id
// this is not the original tweet's id, this is actually the id *of your retweet*
// for backwards compatibility reasons, twitter, despite displaying them differently, actually has retweets stored as normal tweets
// and these normal tweets are attributed to you
// so since it's a tweet, and it's attributed to you, the /i/tweet/pin api goes "well ok" and pins it bc it never checks if its a retweet
@flyxed
Copy link

flyxed commented Oct 10, 2019

getting "SyntaxError: '[object HTMLDocument]' is not a valid selector"
is this why it's currently not working?

@TheEssem
Copy link

getting "SyntaxError: '[object HTMLDocument]' is not a valid selector"
is this why it's currently not working?

you need to be on the old layout

@z4nii
Copy link

z4nii commented Oct 13, 2019

hi, i am having trouble with doing this. could you possibly help me? my twitter is @z4nii if you want to contact me that way. thanks!

@JohnnyMcNuggets
Copy link

JohnnyMcNuggets commented Oct 14, 2019

I'm getting "Failed to load resource: net: : EER_BLOCKED_BY_CLIENT" after I retweet the tweet I want to pin. Is there a fix?
(It worked when I tried it again, my apologies)

@sks316
Copy link

sks316 commented Jun 2, 2020

Old layout is discontinued, consider porting this to the new layout

@twilight-sparkle-irl
Copy link
Author

@sks316 Requires ability to sign requests using oauth, cannot currently figure out obvious way to do this.
Until then, get Twitter oauth keys with R/W access, grab retweet ID (can be done using network inspector), and then run this using twurl:

twurl -d "tweet_mode=extended&id=[retweet ID]" /1.1/account/pin_tweet.json

@rougetimelord
Copy link

I think Twitter killed the loophole for account/pin_tweet when they released v2, trying to get it to pin a retweet status now gets a 404 with 'errors':[{'code': 144, 'message': 'No status found with that ID.'}] as the body even using v1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment