本文整理汇总了Python中twitter.OAuth方法的典型用法代码示例。如果您正苦于以下问题:Python twitter.OAuth方法的具体用法?Python twitter.OAuth怎么用?Python twitter.OAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twitter
的用法示例。
在下文中一共展示了twitter.OAuth方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import twitter [as 别名]
# 或者: from twitter import OAuth [as 别名]
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,
]
示例2: __init__
# 需要导入模块: import twitter [as 别名]
# 或者: from twitter import OAuth [as 别名]
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
示例3: twitter_init
# 需要导入模块: import twitter [as 别名]
# 或者: from twitter import OAuth [as 别名]
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)
示例4: twitter
# 需要导入模块: import twitter [as 别名]
# 或者: from twitter import OAuth [as 别名]
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
示例5: __init__
# 需要导入模块: import twitter [as 别名]
# 或者: from twitter import OAuth [as 别名]
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 = {}
示例6: authenticate
# 需要导入模块: import twitter [as 别名]
# 或者: from twitter import OAuth [as 别名]
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))