設定 tweepy 驗證
在影片中,我們看到如何使用 tweepy 透過 Streaming API 收集 Twitter 資料。tweepy 需要 Twitter 的 API 金鑰來與 Twitter 進行驗證。
在這個練習中,你將從 tweepy 載入幾個物件,並為此套件設定驗證。
API 金鑰 access_token、access_token_secret、consumer_key 和 consumer_secret 已經替你定義好了。
本練習屬於課程
使用 Python 分析社群媒體資料
練習說明
- 從
tweepy模組匯入OAuthHandler和API。 - 將
consumer_key和consumer_secret傳給OAuthHandler。 - 使用
access_token和access_token_secret設定 access token。 - 將
auth物件傳入 API。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
from ____ import ____
from ____ import ____
# Consumer key authentication
auth = OAuthHandler(____, ____)
# Access key authentication
auth.set_access_token(____, ____)
# Set up the API with the authentication handler
api = API(____)