karlicoss / stexport

Export and access your Stackexchange data
MIT License
11 stars 1 forks source link

Update documentation on how to get access_token? #2

Open Cobertos opened 3 years ago

Cobertos commented 3 years ago

It seems like access_token is needed, and requires an implicit OAuth 2.0 flow (or that seems the easiest). I get xtackapi.stackapi.StackAPIError: ('https://api.stackexchange.com/2.2/sites/?pagesize=1000&page=1&filter=xxx&key=xxx&access_token=asdf', 403, 'access_denied', 'keyis not valid for passedaccess_token, token not found (does not exist).') without it

I ended up:

It's verbose to add all of that to the README.md, but may be nice to specify you'll have to manually do the OAuth 2.0 flow yourself. Either in browser or Insomnia or something

karlicoss commented 3 years ago

Ah, whoops! I had this snippet in my secrets.py file

# https://stackapps.com/apps/oauth/view/16169
# TODO move that to stexport instead?
def get_token():
    from subprocess import check_call
    from urllib.parse import urlencode
    # https://api.stackexchange.com/docs/authentication
    qs = [
        ('client_id'   , client_id),
        ('redirect_uri', redirect_uri),
        # https://api.stackexchange.com/docs/authentication#scope
        ('scope'       , 'private_info no_expiry')
    ]
    url = 'https://stackoverflow.com/oauth/dialog?' + urlencode(qs)
    check_call(['xdg-open', url])
    print("Now copy acces_token and put it in the script")

if __name__ == '__main__':
    get_token()

I guess makes sense to implement --login mode or something, similar to instapexport, for example: https://github.com/karlicoss/instapexport#setting-up