認識 Twitter JSON

使用 Python 分析社群媒體資料

Alex Hanna

Computational Social Scientist

Twitter JSON 的內容

{  "created_at": "Thu Apr 19 14:25:04 +0000 2018",
   "id": 986973961295720449,
   "id_str": "986973961295720449",
   "text": "Writing out the script of my @DataCamp class 
            and I can't help but mentally read it back to myself in 
            @hugobowne's voice.",    
   "retweet_count": 0,
   "favorite_count": 1,
      ...  }
  • 轉推與按讚數
  • 語言
  • 回覆哪一則推文
  • 回覆哪位使用者
使用 Python 分析社群媒體資料

子層 JSON 物件

{
        "user": {
            "id": 661613,
            "name": "Alex Hanna, Data Witch",
            "screen_name": "alexhanna",
            "location": "Toronto, ON",
            ...
         }
}
使用 Python 分析社群媒體資料

地點、轉推/引用與 140+ 字推文

  • placecoordinate
    • 含地理定位
  • extended_tweet
    • 超過 140 字的推文
  • retweeted_statusquoted_status
    • 含轉推與引用推文的完整資訊
使用 Python 分析社群媒體資料

存取 JSON

import json

tweet_json = open('tweet-example.json', 'r').read()

tweet = json.loads(tweet_json)
tweet['text']
使用 Python 分析社群媒體資料

推文的子層 JSON

tweet['user']['screen_name']

tweet['user']['name']
tweet['user']['created_at']
使用 Python 分析社群媒體資料

一起來練習吧!

使用 Python 分析社群媒體資料

Preparing Video For Download...