官术网_书友最值得收藏!

  • Python Social Media Analytics
  • Siddhartha Chatterjee Michal Krystyanczuk
  • 132字
  • 2021-07-15 17:24:58

Connect to the API

The following are the steps to connect to the API:

  1. Firstly, we import the required libraries as follows:
import requests 
import json 
  1. Create a params variable that contains your access token.
params = {'access_token': 'YOUR_ACCESS_TOKEN'} 
  1. Make a request to the feed for the Mercedes Benz page.
page_url = 'https://graph.facebook.com/v2.8/MercedesBenzFrance/feed' 
result = requests.get(page_url, params = params) 
  1. Parse the results as a JSON.
data = result.json() 

The data field contains a list of messages with the following fields: message, created_at, and id. We will print the content of messages.

for element in data['data']: 
  print(element['message'] 

This simple method helps us access the content of conversations on Facebook pages. We will use this information to perform data mining and extract insights in Chapter 3, Uncovering Brand Activity, Emotions, and Popularity on Facebook.

主站蜘蛛池模板: 曲麻莱县| 汶上县| 嘉黎县| 临桂县| 湄潭县| 建昌县| 株洲县| 长垣县| 安塞县| 道真| 龙口市| 吴川市| 巩义市| 中牟县| 铁岭县| 永修县| 宿州市| 罗平县| 迁西县| 卓资县| 兴安县| 清原| 思茅市| 凌云县| 无为县| 新宁县| 迭部县| 惠来县| 修水县| 托克逊县| 马尔康县| 昌吉市| 普兰县| 鹿泉市| 榆中县| 乌拉特后旗| 大悟县| 吐鲁番市| 广饶县| 福鼎市| 丰城市|