1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FacebookGraphAPIで取得したJSONをPandasでいじる際の覚書

Posted at

json_nomalizeを使えばいいだけなのだけど、dataを指定するまでに行き着くまでに紆余曲折してしまったので覚書。

graph.py
import requests
import pandas as pd
from pandas.io.json import json_normalize
# package for flattening json in pandas df

import json


access_token = 'xxxxアクセストークンを設定xxxx'
url = 'https://graph.facebook.com/v2.12/xxxよしなにxxxx&access_token=' + access_token


r = requests.get(url)

json_dict = json.loads(r.text)

# ここでdataを指定してあげないとネスト構造が解析できなくなる
df = json_normalize(json_dict['data'])

display(df)

気が向いたら補足を付けます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?