我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django.conf.settings.TWITTER_ACCESS_TOKEN_SECRET。
def get_tweets(request): datas = [] p = ttp.Parser() try: api = twitter.Api( consumer_key=settings.TWITTER_CONSUMER_KEY, consumer_secret=settings.TWITTER_CONSUMER_SECRET, access_token_key=settings.TWITTER_ACCESS_TOKEN, access_token_secret=settings.TWITTER_ACCESS_TOKEN_SECRET ) tweets = api.GetUserTimeline(screen_name='kodlaco') for tweet in tweets: datas.append({ #'text': p.parse(tweet.text).html, 'text': tweet.text, 'id_str': tweet.id_str }) except: datas = [] return HttpResponse(json.dumps(datas), content_type="application/json")
def handle(self, *args, **options): api = twitter.Api(consumer_key=settings.TWITTER_CONSUMER_KEY, consumer_secret=settings.TWITTER_CONSUMER_SECRET, access_token_key=settings.TWITTER_ACCESS_TOKEN_KEY, access_token_secret=settings.TWITTER_ACCESS_TOKEN_SECRET) for currency_symbol in settings.SOCIAL_NETWORK_SENTIMENT_CONFIG['twitter']: print(currency_symbol) results = api.GetSearch("$" + currency_symbol, count=200) for tweet in results: if SocialNetworkMention.objects.filter(network_name='twitter', network_id=tweet.id).count() == 0: snm = SocialNetworkMention.objects.create( network_name='twitter', network_id=tweet.id, network_username=tweet.user.screen_name, network_created_on=datetime.datetime.fromtimestamp(tweet.GetCreatedAtInSeconds()), text=tweet.text, symbol=currency_symbol, ) snm.set_sentiment() snm.save()
def post_microblog_post_on_twitter(microblog_post): api = Twitter( api_key=settings.TWITTER_API_KEY, api_secret=settings.TWITTER_API_SECRET, access_token=settings.TWITTER_ACCESS_TOKEN, access_token_secret=settings.TWITTER_ACCESS_TOKEN_SECRET ) post_content = format_twitter_post(microblog_post) try: api.statuses_update().post(params={'status': post_content}) microblog_post.posted_on_twitter = True microblog_post.save() except ClientError: logger.error( "Tried to post a microblog post on Twitter but got a ClientError, " "check your twitter keys.") raise
def connect(): api = twitter.Api(consumer_key=settings.SOCIAL_AUTH_TWITTER_KEY, \ consumer_secret=settings.SOCIAL_AUTH_TWITTER_SECRET, \ access_token_key=settings.TWITTER_ACCESS_TOKEN_KEY, \ access_token_secret=settings.TWITTER_ACCESS_TOKEN_SECRET) return api