8

Registering your application or script gets you a higher daily quota and is fairly simply; a step by step guide is documented here: I only need a key, what do I do?

However, what if I do want an access token, either to get around the new paging restrictions for anonymous users, to read personal information (e.g. my inbox) or to get write access? Do I have to set up a website so I can use the OAuth flow as described in the documentation?

1 Answer 1

10

It's possible to authenticate yourself via the command line; there's no need to set up a website or so.

  • Open the application page via https://stackapps.com/apps/oauth and make sure the option 'Enable Client Side OAuth Flow' is disabled.
    • You can use any domain (e.g. stackapps.com) as OAuth domain; you don't need to control it.
  • Open the following URL in your browser (add the actual client id from the application page, and the scope with what you actually need - for details, see the documentation): https://stackoverflow.com/oauth?client_id=...&scope=read_inbox,no_expiry,write_access,private_info&redirect_uri=https://stackapps.com
  • After authenticating, you'll get redirected to https://stackapps.com/?code=...; the code ends in )).
  • Execute the following command in a terminal (add the client id and client secret from the application page and the code from the previous step): curl -d "client_id=...&client_secret=...&code=...&redirect_uri=https://stackapps.com" -X POST https://stackoverflow.com/oauth/access_token
  • The result is a simple access_token=... and the token also ends in )).

You can now use that token in combination with your app key, e.g. to read your global inbox with a GET call to https://api.stackexchange.com/2.3/inbox?key=...&access_token=....

Another option is provided here by @rene, but this one is (IMVHO, of course) simpler if you know how to handle the command line and/or you're not particularly fond of JavaScript.

3
  • I was wondering if the ... ends with )) is a feature or a coincidence with the chosen encoding. IOW, do we risk ever seeing a token that doesn't end in )) when we exhausted all the space the token allows for? (probably in 6 to 8 weeks) Commented Mar 22, 2022 at 17:41
  • I have no idea. I thought it was some Base64 dialect I didn't know of, but some investigation did not get me any wiser ... Commented Mar 22, 2022 at 17:45
  • Maybe ASCII85 .... Commented Mar 22, 2022 at 17:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.