TextMining: KeyやToken情報の隠し方, python

スクリプトを公開するときに、いちいちKeyとToken情報を消すのが面倒なのでスクリプトから隠す方法をみつけました。

下の文書のcredentails情報にかかわる部分について説明します。

 

Sentiment analysis on Trump’s tweets using Python

 

情報の収集のためにはTwitter Appを作成し、次の4つの情報を入手する必要があります。

  • Consumer Key (API Key)
  • Consumer Secret (API Secret)
  • Access Token
  • Access Token Secret

これらの情報を下のように書き込んだファイルをcredentials.pyの名で作業フォルダに保存します。

 

# Twitter App access keys for @user
# Consume:
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
# Access:
ACCESS_TOKEN = ''
ACCESS_SECRET = ''

 

次の式で呼び出すことができます。

 

# We import our access keys:
from credentials import * # This will allow us to use the keys as variables
 

 

試しに私のツイートを収集し、最近の5件を表示しました。

 

 

 

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.