Skip to content

Instantly share code, notes, and snippets.

@0xDispatch
Created February 7, 2023 09:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xDispatch/8ea8f1cea701c7209c2579a8a7608380 to your computer and use it in GitHub Desktop.
Save 0xDispatch/8ea8f1cea701c7209c2579a8a7608380 to your computer and use it in GitHub Desktop.
a simple python script to generate Access tokens using twitter official keys.
import requests
from requests_oauthlib import OAuth1
#twitter official keys *Twitter for Android*
consumer_key = "3nVuSoBZnx6U4vzUxf5w"
consumer_secret = "Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys"
#change these to your user&pass
username = "NordsWarrior"
password = "NeverGonnaGiveYouUp"
oauth = OAuth1(
consumer_key,client_secret=consumer_secret
)
r = requests.post(
url="https://api.twitter.com/oauth/access_token",
auth=oauth,
data={
'x_auth_mode': 'client_auth',
'x_auth_username': username,
'x_auth_password': password})
print(r.content)
@Wouze
Copy link

Wouze commented Feb 7, 2023

much, Much, better one based on yours
be gentle 👍

import requests
from requests_oauthlib import OAuth1

# needs ! pip install tweepy
import tweepy


def get_api(username='', password='') -> tweepy.API:
    
    """
    This function takes username and password and return the API object from tweepy
    """

    #twitter official keys *Twitter for Android*
    consumer_key = "3nVuSoBZnx6U4vzUxf5w"
    consumer_secret = "Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys"

    oauth = OAuth1(
    consumer_key,client_secret=consumer_secret
    )

    r = requests.post(
        url="https://api.twitter.com/oauth/access_token",
        auth=oauth,
        data={
        'x_auth_mode': 'client_auth',
        'x_auth_username': username,
        'x_auth_password': password})

    resp = str(r.content)

    if resp == "b'Invalid user name or password'":
        raise Exception("Invalid user name or password")
    
    # python dictionary comprehension awesome sexy magic :)
    resp = {i.split('=')[0]:i.split('=')[1] for i in resp[2:-1].split("&")}

    # api setup
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(resp['oauth_token'], resp['oauth_token_secret'])
    api = tweepy.API(auth)

    return api
        
api = get_api("NordsWarrior", "NeverGonnaLetYouDown")

print(api.verify_credentials().screen_name)

@0xDispatch
Copy link
Author

much, Much, better one based on yours be gentle 👍

import requests
from requests_oauthlib import OAuth1

# needs ! pip install tweepy
import tweepy


def get_api(username='', password='') -> tweepy.API:
    
    """
    This function takes username and password and return the API object from tweepy
    """

    #twitter official keys *Twitter for Android*
    consumer_key = "3nVuSoBZnx6U4vzUxf5w"
    consumer_secret = "Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys"

    oauth = OAuth1(
    consumer_key,client_secret=consumer_secret
    )

    r = requests.post(
        url="https://api.twitter.com/oauth/access_token",
        auth=oauth,
        data={
        'x_auth_mode': 'client_auth',
        'x_auth_username': username,
        'x_auth_password': password})

    resp = str(r.content)

    if resp == "b'Invalid user name or password'":
        raise Exception("Invalid user name or password")
    
    # python dictionary comprehension awesome sexy magic :)
    resp = {i.split('=')[0]:i.split('=')[1] for i in resp[2:-1].split("&")}

    # api setup
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(resp['oauth_token'], resp['oauth_token_secret'])
    api = tweepy.API(auth)

    return api
        
api = get_api("NordsWarrior", "NeverGonnaLetYouDown")

print(api.verify_credentials().screen_name)

Nice work !

@0xDispatch
Copy link
Author

these keys work as well.

#Twitter for Mac
consumer_key = "3rJOl1ODzm9yZy63FACdg"
consumer_secret = "5jPoQ5kQvMJFDYRNE8bQ4rHuds4xJqhvgNJM4awaE8"

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