Python twitter.OAuth() Examples
The following are 7
code examples of twitter.OAuth().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twitter
, or try the search function
.
Example #1
Source File: twitter.py From ThreatIngestor with GNU General Public License v2.0 | 6 votes |
def __init__(self, api_key, api_secret_key, access_token, access_token_secret, status, **kwargs): self.api = twitter.Twitter(auth=twitter.OAuth(access_token, access_token_secret, api_key, api_secret_key)) self.status = status # Validate status, for better error handling. if not isinstance(self.status, str): raise threatingestor.exceptions.IngestorError(f"Invalid 'status' config: {self.status}") super(Plugin, self).__init__(kwargs.get('artifact_types'), kwargs.get('filter_string'), kwargs.get('allowed_sources')) self.artifact_types = kwargs.get('artifact_types') or [ threatingestor.artifacts.URL, threatingestor.artifacts.Domain, threatingestor.artifacts.Hash, threatingestor.artifacts.IPAddress, ]
Example #2
Source File: twitter.py From ThreatIngestor with GNU General Public License v2.0 | 5 votes |
def __init__(self, name, api_key, api_secret_key, access_token, access_token_secret, defanged_only=True, **kwargs): self.name = name self.api = twitter.Twitter(auth=twitter.OAuth(access_token, access_token_secret, api_key, api_secret_key)) # Let the user decide whether to include non-obfuscated URLs or not. self.include_nonobfuscated = not defanged_only # Support for full tweet tweet_param = {'tweet_mode': 'extended'} kwargs.update(tweet_param) # Forward kwargs. # NOTE: No validation is done here, so if the config is wrong, expect bad results. self.kwargs = kwargs # Decide which endpoint to use based on passed arguments. # If slug and owner_screen_name, use List API. # If screen_name or user_id, use User Timeline API. # If q is set, use Search API. # Otherwise, default to mentions API. self.endpoint = self.api.statuses.mentions_timeline if kwargs.get('slug') and kwargs.get('owner_screen_name'): self.endpoint = self.api.lists.statuses elif kwargs.get('screen_name') or kwargs.get('user_id'): self.endpoint = self.api.statuses.user_timeline elif kwargs.get('q'): self.endpoint = self.api.search.tweets
Example #3
Source File: afl_stats.py From afl-utils with Apache License 2.0 | 5 votes |
def twitter_init(config): try: config['twitter_creds_file'] = os.path.abspath(os.path.expanduser(config['twitter_creds_file'])) if not os.path.exists(config['twitter_creds_file']): twitter.oauth_dance("fuzzer_stats", config['twitter_consumer_key'], config['twitter_consumer_secret'], config['twitter_creds_file']) oauth_token, oauth_secret = twitter.read_token_file(config['twitter_creds_file']) twitter_instance = twitter.Twitter(auth=twitter.OAuth(oauth_token, oauth_secret, config['twitter_consumer_key'], config['twitter_consumer_secret'])) return twitter_instance except (twitter.TwitterHTTPError, URLError): print_err("Network error, twitter login failed! Check your connection!") sys.exit(1)
Example #4
Source File: scraper.py From RTA with Apache License 2.0 | 5 votes |
def twitter(self): """ Keywords based search on twitter and returns the recent results based on the same """ message = "" count = self.collection.count() twitter = Twitter(auth = OAuth(self.access_key, self.access_secret, self.consumer_key, self.consumer_secret)) for keyword in self.twitter_keywords: query = twitter.search.tweets(q = keyword) for result in query['statuses']: try: data = {"id": count+1, "source": "twitter", "timestamp": datetime.now()} data['tweet'] = result['text'] data['name'] = result["user"]["screen_name"] data['url'] = "https://twitter.com/" + data["name"] + "/status/" + str(result['id']) data['search_string'] = keyword try: dataid = self.collection.insert(data) except DuplicateKeyError as e: continue count += 1 # Slack push notification length = 82 - len(data['url']) message += "\nURL: " + data['url'] + " search string: ".rjust(length) + keyword except Exception as e: print(e) pass if message: print(self.G + "[+] Twitter" + self.B + message + self.W + "\n") self.message += "\n*Twitter*:\n```" self.message += message self.message += "\n```\n*Github*:\n" return
Example #5
Source File: api_wrapper.py From gazouilloire with GNU General Public License v3.0 | 5 votes |
def __init__(self, api_keys): self.oauth = OAuth(api_keys['OAUTH_TOKEN'], api_keys['OAUTH_SECRET'], api_keys['KEY'], api_keys['SECRET']) self.oauth2 = OAuth2(bearer_token=json.loads(Twitter(api_version=None, format="", secure=True, auth=OAuth2(api_keys['KEY'], api_keys['SECRET'])).oauth2.token(grant_type="client_credentials"))['access_token']) self.api = { 'user': Twitter(auth=self.oauth), 'app': Twitter(auth=self.oauth2) } self.waits = {} self.auth = {}
Example #6
Source File: twitter_timeline.py From services-to-wordcloud with MIT License | 5 votes |
def authenticate(self): self.auth = twitter.Twitter(auth=twitter.OAuth(self.access_token, self.access_secret, self.consumer_key, self.consumer_secret)) return bool(isinstance(self.auth, twitter.api.Twitter))
Example #7
Source File: twitter_user_locations.py From services-to-wordcloud with MIT License | 5 votes |
def authenticate(self): self.auth = twitter.Twitter(auth=twitter.OAuth(self.access_token, self.access_secret, self.consumer_key, self.consumer_secret)) return bool(isinstance(self.auth, twitter.api.Twitter))