Twitter API 與驗證

Python 資料匯入進階

Hugo Bowne-Anderson

Data Scientist at DataCamp

本節你將學到

  • 如何從 Twitter API 串流資料
  • 如何用關鍵字過濾推文
  • 認識 API 驗證與 OAuth

 

ch_3_1.003.png

Python 資料匯入進階

本節你將學到

  • 如何從 Twitter API 串流資料
  • 如何用關鍵字過濾推文
  • 認識 API 驗證與 OAuth
  • 如何使用 Tweepy Python 套件

ch_3_1.006.png

Python 資料匯入進階

存取 Twitter API

ch_3_1.008.png

Python 資料匯入進階

存取 Twitter API

ch_3_1.009.png

Python 資料匯入進階

存取 Twitter API

ch_3_1.011.png

Python 資料匯入進階

存取 Twitter API

ch_3_1.013.png

Python 資料匯入進階

Twitter 提供多種 API

ch_3_1.015.png

Python 資料匯入進階

Twitter 提供多種 API

ch_3_1.017.png

Python 資料匯入進階

Twitter 提供多種 API

ch_3_1.018.png

Python 資料匯入進階

Twitter 提供多種 API

ch_3_1.020.png

Python 資料匯入進階

Twitter 提供多種 API

ch_3_1.022.png

Python 資料匯入進階

推文以 JSON 格式回傳

ch_3_1.024.png

Python 資料匯入進階

推文以 JSON 格式回傳

ch_3_1.026.png

Python 資料匯入進階

使用 Tweepy:驗證

tweets.py

import tweepy, json

access_token = "..." access_token_secret = "..." consumer_key = "..." consumer_secret = "..."
Python 資料匯入進階

使用 Tweepy:串流推文!

tweets.py

# Create Streaming object
stream = tweepy.Stream(consumer_key, consumer_secret, 
                       access_token, access_token_secret)

# This line filters Twitter Streams to capture data by keywords: stream.filter(track=['apples', 'oranges'])
Python 資料匯入進階

一起來練習吧!

Python 資料匯入進階

Preparing Video For Download...