How to retrieve Gists by sort option (recently updated etc)

53 views Asked by At

I swear I was able to retrieve Gists by a particular sorting option by using this URL structure.

url = 'https://api.github.com/gists?sort=updated&direction=desc', but now it keeps retrieving the Gists by the default Recently created.

Has something changed? I couldn't find anything in the docs. It looks like the URL in the browser has changed, though modifying my code doesn't help either.

https://gist.github.com/Username?direction=desc&sort=updated

url = 'https://api.github.com/gists?direction=desc&sort=updated'

It's for a private GitHub account and this is the rest of the retrieval code, should it matter,

# Headers for the request
headers = {'Authorization': f'Bearer {apiKey}'}

url = 'https://api.github.com/gists?sort=updated&direction=desc'

# Make a request to the URL to retrieve the Gists
response = requests.get(url, headers=headers)
data = response.json()

Thank you

1

There are 1 answers

0
DevGW On

The only officially accepted query parameters for "List gists for the authenticated user" are:

  • since
  • per_page
  • page

This is according to the latest api version documentation v 2022-11-28.

As a side note the api query parameters are identical for public vs private. The difference is that if you authenticate and have access to the private gists you will also see those among the responses.

More information can be found here