nytimes / public_api_specs

The API Specs (in OpenAPI/Swagger) for the APIs available from developer.nytimes.com
http://developer.nytimes.com
Apache License 2.0
136 stars 40 forks source link

Most Popular API: share_count returns index number #53

Closed stevenlis closed 5 years ago

stevenlis commented 5 years ago

The share_count in the result object returns the index number instead of how many times an article got shared.

base_url = 'https://api.nytimes.com/svc/mostpopular/v2'
path = 'shared'
period = 7
share_type = 'email'

params = {}
params['api-key'] = 'YOUR_KEY'

url = f'{base_url}/{path}/{period}/{share_type}'

r = requests.get(url, params=params)
results = r.json()['results']
for index, result in enumerate(results, start=1):
    print(result['share_count'] == index)
    print(result['share_count'], result['title'])
True
1 Things People Say to Their Dogs
True
2 The Vegetarians Who Turned Into Butchers
True
3 A Hidden Gem of Rhode Island
True
4 The 50 Best TV Shows on Netflix Right Now
True
5 How Trump and Xi Can Make America and China Poor Again
True
6 Russian Land of Permafrost and Mammoths Is Thawing
True
7 The Who-Can-Beat Trump Test Leads to Kamala Harris
True
8 Where Hollywood’s Golden Age Stars Found Safe Harbor
True
9 White Sand, Clear Water
True
10 36 Hours on Outer Cape Cod
True
11 Was Trump’s El Paso Visit a Turning Point?
True
12 Trump’s Biggest and Most Dangerous Lie
True
13 Cancer Treatment at the End of Life
True
14 The Math Equation That Tried to Stump the Internet
True
15 What Explains U.S. Mass Shootings? International Comparisons Suggest an Answer
True
16 On Kauai, Paradise Requires Four Wheel Drive
True
17 Your Baby Boomer Report Card
True
18 Trump, Tax Cuts and Terrorism
True
19 James Comey: The President Has Exploited the Power of Racism
True
20 Craving Freedom, Japan’s Women Opt Out of Marriage
stevenlis commented 5 years ago

It seems like the email_count in the results object from GET /emailed/{period}.json also has the same problem. Am I missing something?

The num_results object returns a single integer, but the results object contains 20 different articles. Do this mean the num_results represent how many times those 20 articles got shared in total?

nyt-hughmandeville commented 5 years ago

num_results returns the total number of articles on the most emailed list. The API returns 20 at a time. So if you want to see them all, you'll need to paginate thru the results, using offset query parameter (offset=0, offset=20, offset=40, ...). The list starts becoming pretty unmeaningful after about 20 because of the number of times shared gets pretty low.

The email_count was originally there to show total number of times the article was emailed. But it was decided that we didn't want to publish that info. To not break old code, we left it in the response, but just set it to rank. We should probably just remove the field to prevent confusion.

stevenlis commented 5 years ago

@nyt-hughmandeville Thanks, man. This makes sense now.

The API returns 20 at a time.

Are they sorted? so the first one is the most shared and the second one is the second most shared, and so on... right?

But it was decided that we didn't to publish that info.

Is there any other way I can have access to how many times each individual article was shared or emailed? Or does this mean that they're not open to the public for good?

nyt-hughmandeville commented 5 years ago

they are sorted, most emailed article is first, second most emailed is second, ...

currently there is intentionally no way to get the shared counts.

stevenlis commented 5 years ago

Thanks for the info buddy. I hope you guys could put a little bit more details for the doc.

stevenlis commented 5 years ago

@nyt-hughmandeville Is there a way to get the most shared article title from...let's say... the day before yesterday or something? of course without a time machine.

nyt-hughmandeville commented 5 years ago

You would have to call the API and save off the results each day. The list changes through out the day as well.