当前位置: 首页>>代码示例>>Python>>正文


Python OAuthHandler.set_access_token方法代码示例

本文整理汇总了Python中tweepy.OAuthHandler.set_access_token方法的典型用法代码示例。如果您正苦于以下问题:Python OAuthHandler.set_access_token方法的具体用法?Python OAuthHandler.set_access_token怎么用?Python OAuthHandler.set_access_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tweepy.OAuthHandler的用法示例。


在下文中一共展示了OAuthHandler.set_access_token方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_tweepy_stream

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
 def create_tweepy_stream(self):
     # This handles Twitter authentication and the connection to Twitter Streaming API
     l = TweepyStreamListener(self.async_queue)
     auth = OAuthHandler(secrets.consumer_key, secrets.consumer_secret)
     auth.set_access_token(secrets.access_token, secrets.access_token_secret)
     stream = Stream(auth, l)
     return stream
开发者ID:art-vybor,项目名称:twnews,代码行数:9,代码来源:fetcher.py

示例2: authenticate

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
	def authenticate(self): 
		"""
		Set up the connection
		"""
		auth = OAuthHandler(self.consumer_key, self.consumer_secret)
		auth.set_access_token(self.access_token, self.access_token_secret)
		return(auth)
开发者ID:carrillo,项目名称:social-media-analyst,代码行数:9,代码来源:twitter_auth.py

示例3: unwrapped_callback

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
    def unwrapped_callback(self, resp):
        if resp is None:
            raise LoginCallbackError(_("You denied the request to login"))

        # Try to read more from the user's Twitter profile
        auth = TwitterOAuthHandler(self.consumer_key, self.consumer_secret)
        if self.access_key is not None and self.access_secret is not None:
            auth.set_access_token(self.access_key, self.access_secret)
        else:
            auth.set_access_token(resp['oauth_token'], resp['oauth_token_secret'])
        api = TwitterAPI(auth)
        try:
            twinfo = api.lookup_users(user_ids=[resp['user_id']])[0]
            fullname = twinfo.name
            avatar_url = twinfo.profile_image_url_https.replace('_normal.', '_bigger.')
        except TweepError:
            fullname = None
            avatar_url = None

        return {'userid': resp['user_id'],
                'username': resp['screen_name'],
                'fullname': fullname,
                'avatar_url': avatar_url,
                'oauth_token': resp['oauth_token'],
                'oauth_token_secret': resp['oauth_token_secret'],
                'oauth_token_type': None,  # Twitter doesn't have token types
                }
开发者ID:gonrin,项目名称:lastuser,代码行数:29,代码来源:twitter.py

示例4: main

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
def main():

    auth = OAuthHandler(ckey, csecret)
    auth.set_access_token(atoken, asecret)
    api = tweepy.API(auth)

    # specify the main machine's server address
    couch = couchdb.Server('http://ccteam24:[email protected]:5984/')
    try:
        database = couch['train']
    except:
        database = couch.create('train')

    cursor = tweepy.Cursor(api.search, geocode="39.091919,-94.5757195,1000km", since="2015-05-03",
                           until="2015-05-10", lang="en").items()
    while True:
        try:
            tweet = cursor.next()

            database.save(tweet)
        except tweepy.TweepError:
            print 'waiting...'
            time.sleep(60*15)
        except StopIteration:
            break
开发者ID:xpendous,项目名称:sandiego,代码行数:27,代码来源:pastTweets.py

示例5: stream_twitter

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
def stream_twitter(battle_id):
    #Avoiding circular import
    from battle.models import Battle

    battle = Battle.objects.get(id=battle_id)
    if battle.end_time < timezone.now():
        return

    battle.battlehashtags_set.update(typos=0, words=0)
    battle_hashtags = battle.battlehashtags_set.all().prefetch_related('hashtag')
    if battle_hashtags.count() == 0:
        return

    hashtag_values = [x.hashtag.value for x in battle_hashtags]

    listener = TwitterStreamListener(battle_hashtags)
    auth = OAuthHandler(
        settings.TWITTER_CONSUMER_KEY,
        settings.TWITTER_CONSUMER_SECRET
    )

    auth.set_access_token(
        settings.TWITTER_ACCESS_TOKEN,
        settings.TWITTER_ACCESS_TOKEN_SECRET
    )

    stream = Stream(auth, listener)

    delay = battle.end_time - timezone.now()
    Timer(delay.total_seconds(), stream.disconnect).start()

    stream.filter(track=hashtag_values, languages=['en'])
开发者ID:bestan,项目名称:battle-hashtags,代码行数:34,代码来源:tasks.py

示例6: main

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
def main():
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    backend = FileBackend("./test-db")
    stream = Stream(auth, l)
    stream.filter(track=['トレクル'])
开发者ID:gosu-clan,项目名称:twanki,代码行数:9,代码来源:twanki.py

示例7: handle

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
    def handle(self, *args, **options):
        
        politicians = Politician.objects.all();

        politician_keywords = []
        for politician in politicians:
            politician_keywords.append(politician.first_name + " " + politician.last_name)
            if politician.twitter_url:
                indexSlash = politician.twitter_url.rfind("/")
                indexQuestionMark = politician.twitter_url.rfind("?")
                if indexQuestionMark != -1:
                    twitter = politician.twitter_url[indexSlash+1:indexQuestionMark]
                else:
                    twitter = politician.twitter_url[indexSlash+1:]
                politician_keywords.append(twitter)
        
        # create instance of the tweepy tweet stream listener
        listener = TweetStreamListener()

        # set twitter keys/tokens
        auth = OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)

        # create instance of the tweepy stream
        stream = Stream(auth, listener)


        # search twitter for "congress" keyword
        stream.filter(track=politician_keywords)
        
开发者ID:icanfreaku,项目名称:politician_blog,代码行数:31,代码来源:twitter_stream_collector.py

示例8: _request_tweets

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
    def _request_tweets(self, search_word, since_id):
        auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        auth.set_access_token(self.access_token, self.access_secret)

        tweets = []
        api = tweepy.API(auth)
        max_id = None
        new_since_id = None
        total = 0
        logger.info("start search by %s" % search_word)
        while True:
            tweets_batch = api.search(search_word, max_id=max_id, since_id=since_id)
            logger.info("get " + str(len(tweets_batch)) + " tweets by '" + search_word + "'")
            if not new_since_id: new_since_id = tweets_batch.since_id
            if max_id == tweets_batch.max_id: break

            max_id = tweets_batch.max_id
            total += len(tweets_batch)

            for tweet in tweets_batch:
                tweets.append(tweet._json)

            if not max_id:
                break

        logger.info("done with search found %s new tweets" % total)
        return new_since_id, tweets
开发者ID:mishadev,项目名称:stuff,代码行数:29,代码来源:dataproviders.py

示例9: main

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
 def main(self):
     #twitter authorization
     auth = OAuthHandler(AuthDetails.consumer_key, AuthDetails.consumer_secret)
     auth.set_access_token(AuthDetails.access_token, AuthDetails.access_token_secret)
     language = 'en'
     pt = ProcessTweet()
     searchTerm = pt.unicodetostring(self.searchTerm)
     stopAt = pt.unicodetostring(self.stopAt)
     #calls method to train the classfier
     tr = Training()
     (priors, likelihood) = tr.starttraining()
     #stream tweets from twitter
     twitterStream = Stream(auth, Listener(searchTerm, stopAt))
     twitterStream.filter(track=[searchTerm], languages=[language])
     sen = Sentiment()
     sentiment_tally = Counter()
     (sentiment_tally, tweet_list) = sen.gettweetstoanalyse(priors, likelihood, searchTerm)
     tr = Training()
     sen = Sentiment()
     (neutral, positive, negative) = sen.analyse(sentiment_tally)
     tweet_list = self.edittweetlists(tweet_list)
     #truncate streamtweets table
     self.removetweetsfromdatabase()
     #save training data
     tr.savetrainingdatatodb(priors, likelihood)
     return (neutral, positive, negative, tweet_list)
开发者ID:dmaher,项目名称:NaiveBayesSentimentAnalysis,代码行数:28,代码来源:run.py

示例10: run_twitter_query

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
def run_twitter_query():
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    stream = Stream(auth, l)
    #names = list(np.array(get_companies())[:,1])
    #print names[num1:num2]
    d = hand_made_list()
    search_list = []
    for key, value in d.items():
        if key == 'SPY':
            search_list.append(value[0]) # append the full anme of the symbol
            search_list.append('#SP500') # Don't append #SPY because it's not helpful
            search_list.append('$SP500')
        elif key == 'F':
            # search_list.append(value[0]) # append the full name of the symbol
            search_list.append('Ford') # append the name of the symbol
        elif key == 'GE':
            search_list.append('General Electric') # append the full anme of the symbol
        elif key == 'S':
            search_list.append('Sprint') # append the full anme of the symbol
        elif key == 'T':
            search_list.append('AT&T') # append the full anme of the symbol
        elif key == 'MU':
            search_list.append('Micron Tech') # append the full anme of the symbol
        elif key == 'TRI':
            search_list.append('Thomson Reuters') # append the full anme of the symbol
        else:
            for cell in value:
                search_list.append(cell)

    stream.filter(track=search_list)
开发者ID:gravity226,项目名称:NASDAQ,代码行数:34,代码来源:save_stock_tweets.py

示例11: process

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
    def process(self, statement):
        confidence = self.classifier.classify(statement.text.lower())
        tokens = nltk.word_tokenize(str(statement))
        tagged = nltk.pos_tag(tokens)
        nouns = [word for word, pos in tagged if
                 (pos == 'NN' or pos == 'NNP' or pos =='JJ' or pos == 'NNS' or pos == 'NNPS')]
        downcased = [x.lower() for x in nouns]
        searchTerm = " ".join(downcased).encode('utf-8')
        #"http://where.yahooapis.com/v1/places.q('Place name')?appid=yourappidhere"
        st=""
        if len(nouns) != 0:
            auth = OAuthHandler(twitter_consumer_key, twitter_consumer_secret)
            auth.set_access_token(twitter_access_key, twitter_access_secret)

            api = tweepy.API(auth)
            for status in tweepy.Cursor(api.search, q='#'+searchTerm).items(20):
                st = st+status.text
            response = Statement("Jarvis: "+st)
        else:
            response = Statement("Jarvis: "+"Sorry sir, Nothing Found")
        return confidence, response


#what's trending in city
#movie reviews
#people talking about some topic
开发者ID:anirudh24,项目名称:self_aware_bot,代码行数:28,代码来源:tweet_tag.py

示例12: __init__

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
class MainRunner:
    def __init__(self, conf):
        self._conf = conf
        self._out = None
        self.listeners = []
        self._auth = OAuthHandler(conf.consumer_key, conf.consumer_secret)
        self._auth.set_access_token(conf.access_token, conf.access_token_secret)
        self._run_listener()

    def _run_listener(self):
        listener = Listener(self.out, self._conf.places)
        stream = Stream(self._auth, listener)
        locations = []
        for city in self._conf.places:
            locations.extend(city['southwest'].values())
            locations.extend(city['northeast'].values())
        stream.filter(locations=locations)

    @property
    def out(self):
        if self._out is None:
            try:
                self._out = open(self._conf.output, 'a')
            except FileNotFoundError:
                if path.exists('output.txt'):
                    self._out = open('output.txt', 'a')
                else:
                    self._out = open('output.txt', 'a')
        return self._out

    def __del__(self):
        self.out.close()
开发者ID:litleleprikon,项目名称:bachelor_paper,代码行数:34,代码来源:main_runner.py

示例13: minetweets

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
def minetweets():
    line = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    stream = Stream(auth, line)
    # stream.filter(track=['Watson', 'Cognitive', 'Machine Learning'])
    stream.filter(track=args, languages=["en"])
开发者ID:agrimrules,项目名称:SocialAnalytics,代码行数:9,代码来源:socialPy.py

示例14: init_stream

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
 def init_stream(self):
     self.q = Queue()
     self.keywords = []
     self.listener = TwitterStreamListener(self.keywords, self.q)
     auth = OAuthHandler(config.con_secret, config.con_secret_key)
     auth.set_access_token(config.token, config.token_key)
     self.stream = Stream(auth, self.listener)
开发者ID:theddnc,项目名称:sentiment-app,代码行数:9,代码来源:twitter_crawler.py

示例15: stream

# 需要导入模块: from tweepy import OAuthHandler [as 别名]
# 或者: from tweepy.OAuthHandler import set_access_token [as 别名]
def stream(buff, terms):
    l = StdOutListener(buff)
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    stream = Stream(auth, l)
    stream.filter(track=[terms])
开发者ID:jaywreddy,项目名称:QuantSentimentAnalysis,代码行数:9,代码来源:scraper.py


注:本文中的tweepy.OAuthHandler.set_access_token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。