How to get 'user' data with stackoverflow api?

1.1k Views Asked by At

I want to see the 'user(specifically, user's display_name') data using Stackoverflow's API.

I'm using and reading the docs about StackExchange API, and still didn't get the idea about 'fetch' and anything about get the data.

Using 'beautifulsoup' or any crawling code, is it the only way to get the data?

from stackapi import StackAPI

SITE = StackAPI('stackoverflow')
users = SITE.fetch('users')

print(users['items'])
1

There are 1 best solutions below

0
dogekali On BEST ANSWER

Following the documentation for the StackAPI python library, the method skeleton is fetch(endpoint=None, page=1, key=None, filter='default', **kwargs).

So your api call will look something like:

from stackapi import StackAPI
SITE = StackAPI('stackoverflow')
SITE.page_size = 5 # limits to 5 returned results for demo purpose
users = SITE.fetch('users', filter='!)mYVom7)TA9')
print(users['items'])

where the filter code was obtained from the get users docs for the api.

Returns:

[{'display_name': 'Jon Skeet'}, {'display_name': 'Gordon Linoff'}, {'display_name': 'VonC'}, {'display_name': 'BalusC'}, {'display_name': 'Darin Dimitrov'}]