Assignment- Web APIs
@author:Joseph Simone
The New York Times web site provides a rich set of APIs, as described here: https://developer.nytimes.com/apis
You’ll need to start by signing up for an API key. Your task is to choose one of the New York Times APIs, construct an interface in Python to read in
the JSON data & transform it into a pandas DataFrame.
I decided to use the most sharded on Facebook API From NYT Dev API Website
https://developer.nytimes.com/docs/most-popular-product/1/overview
import requests
import json
from IPython.display import display
import pandas as pd
your_key = "FptvCLy8m9fKva5WGwlGQc2OJEjOJug5"
url = 'https://api.nytimes.com/svc/mostpopular/v2/shared/1/facebook.json?api-key='+ your_key
r = requests.get(url)
json_data = json.loads(r.text)
df = pd.DataFrame(json_data)
display(df.head(10))
| copyright | num_results | results | status | |
|---|---|---|---|---|
| 0 | Copyright (c) 2019 The New York Times Company…. | 1095 | {‘count_type’: ‘SHARED-FACEBOOK’, ‘org_facet’:… | OK |
| 1 | Copyright (c) 2019 The New York Times Company…. | 1095 | {‘count_type’: ‘SHARED-FACEBOOK’, ‘org_facet’:… | OK |
| 2 | Copyright (c) 2019 The New York Times Company…. | 1095 | {‘count_type’: ‘SHARED-FACEBOOK’, ‘org_facet’:… | OK |
| 3 | Copyright (c) 2019 The New York Times Company…. | 1095 | {‘count_type’: ‘SHARED-FACEBOOK’, ‘org_facet’:… | OK |
| 4 | Copyright (c) 2019 The New York Times Company…. | 1095 | {‘count_type’: ‘SHARED-FACEBOOK’, ‘org_facet’:… | OK |
| 5 | Copyright (c) 2019 The New York Times Company…. | 1095 | {‘count_type’: ‘SHARED-FACEBOOK’, ‘org_facet’:… | OK |
| 6 | Copyright (c) 2019 The New York Times Company…. | 1095 | {‘count_type’: ‘SHARED-FACEBOOK’, ‘org_facet’:… | OK |
| 7 | Copyright (c) 2019 The New York Times Company…. | 1095 | {‘count_type’: ‘SHARED-FACEBOOK’, ‘org_facet’:… | OK |
| 8 | Copyright (c) 2019 The New York Times Company…. | 1095 | {‘count_type’: ‘SHARED-FACEBOOK’, ‘org_facet’:… | OK |
| 9 | Copyright (c) 2019 The New York Times Company…. | 1095 | {‘count_type’: ‘SHARED-FACEBOOK’, ‘org_facet’:… | OK |