當前位置: 首頁>>代碼示例>>Python>>正文


Python twitter.OAuth方法代碼示例

本文整理匯總了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,
        ] 
開發者ID:InQuest,項目名稱:ThreatIngestor,代碼行數:19,代碼來源:twitter.py

示例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 
開發者ID:InQuest,項目名稱:ThreatIngestor,代碼行數:29,代碼來源:twitter.py

示例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) 
開發者ID:rc0r,項目名稱:afl-utils,代碼行數:16,代碼來源:afl_stats.py

示例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 
開發者ID:flipkart-incubator,項目名稱:RTA,代碼行數:41,代碼來源:scraper.py

示例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 = {} 
開發者ID:medialab,項目名稱:gazouilloire,代碼行數:11,代碼來源:api_wrapper.py

示例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)) 
開發者ID:vdmitriyev,項目名稱:services-to-wordcloud,代碼行數:7,代碼來源:twitter_timeline.py


注:本文中的twitter.OAuth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。