Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation on how to get access_token? #2

Open
Cobertos opened this issue Mar 9, 2021 · 1 comment
Open

Update documentation on how to get access_token? #2

Cobertos opened this issue Mar 9, 2021 · 1 comment

Comments

@Cobertos
Copy link
Contributor

Cobertos commented Mar 9, 2021

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:

  • Having to enable Enable Client Side OAuth Flow
  • Creating a link like https://stackoverflow.com/oauth/dialog?client_id=[client_id]&scope=private_info,no_expiry&redirect_uri=https://stackexchange.com according to the auth docs
  • Getting the access_token from the return hash in the browser

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

@Cobertos Cobertos changed the title Update documentation to note access_token is not needed? Update documentation on how to get access_token? Mar 9, 2021
@karlicoss
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants