nltk.twitter.util module

Authentication utilities to accompany twitterclient.

class nltk.twitter.util.Authenticate[source]

Bases: object

Methods for authenticating with Twitter.

__init__()[source]
load_creds(creds_file=None, subdir=None, verbose=False)[source]

Read OAuth credentials from a text file.

File format for OAuth 1:

app_key=YOUR_APP_KEY
app_secret=YOUR_APP_SECRET
oauth_token=OAUTH_TOKEN
oauth_token_secret=OAUTH_TOKEN_SECRET

File format for OAuth 2:

app_key=YOUR_APP_KEY
app_secret=YOUR_APP_SECRET
access_token=ACCESS_TOKEN
Parameters

file_name (str) – File containing credentials. None (default) reads data from TWITTER/’credentials.txt’

nltk.twitter.util.add_access_token(creds_file=None)[source]

For OAuth 2, retrieve an access token for an app and append it to a credentials file.

nltk.twitter.util.credsfromfile(creds_file=None, subdir=None, verbose=False)[source]

Convenience function for authentication

nltk.twitter.util.guess_path(pth)[source]

If the path is not absolute, guess that it is a subdirectory of the user’s home directory.

Parameters

pth (str) – The pathname of the directory where files of tweets should be written