For OAuth Authorization Code Flow this is the process which I found from documentation and one of the posts.
Step 1 - send user to loginRedirectURL https://id.twitch.tv/oauth2/authorize
where I accepted/authorized the connection
Step 2 - user is sent to your redirectURI with a code https://<your registered redirect URI>/?code=<authorization code>
Step 3 -you exchange the code for a token, aka tokenExchangeURL https://id.twitch.tv/oauth2/token
Here my question is how do we get code in step 2 programmatically?
Is there any specific library? I was thinking of using python requests or urllib library?
3ventic
3
How you get the query or search parameter depends on the HTTP server and/or library youâre using. Refer to the documentation for the library youâre using.
Can you suggest which library i can use to get the code?
For me its working fine is POSTMAN or in browser just want to know how I can get redirected url code link via Python
Firs google result, describes a python solution
i reviewed it but what Iâm having issue is described below
authorize_url = âhttps://api.twitch.tv/kraken/oauth2/authorizeâ
client_id = âSomethingâ
RESPONSE_TYPE=code
SCOPE = âanalytics:read:gamesâ
COMPLETE_URL = authorize_url+â?client_id=â+client_id+â&redirect_uri=â+callback_uri+â&response_type=â+RESPONSE_TYPE+â&scope=â+SCOPE
print(COMPLETE_URL)
r = requests.head(url=COMPLETE_URL,allow_redirects=True)
print(r.url)
Output recieved:
But the output expected should be
http://localhost/?code=Some CODE l&scope=analytics%3Aread%3Agames
BarryCarlyon
So I want to know which method I should be using is requests or urllib library or any other library which would give me that URL
The first step of outh is to redirect the user to Twitch
You seem to be making a HEAD request.
There is no need to @ people. The Forum notifies me when you reply.
Iâm new to the platform. Yes I wonât use â@â
Also requests. get gives the same response
r = requests.get(url=COMPLETE_URL,allow_redirects=True)
Instead can you suggest what I should be using?
You shouldnât be GETting or POSTing or HEADing at all
You need to be redirecting the user to Twitch to accept or deceline your apps access to their account.
Like in this implicit auth example
https://barrycarlyon.github.io/twitch_misc/authentication/implicit_auth/
Step 1) Redirects you to Twitch.
Step 2) Accept or decline
Step 3) you come back with an access token or an error message
With regular oAuth, like what you are doing
Step 1) Redirects you to Twitch.
Step 2) Accept or decline
Step 3) user comes back with a ?code or an error message
Step 4) Exchange the ?code for an access and refresh token
So iâm able to redirect and have âAuthorizedâ like this
So next time when I paste the URL in browser I get the code but the same if I want to do it with Python can you suggest what I should be doing?
Your Python website presents a link for users to click on
users click the link and are taken to Twitch
users accept/decline the apps access
user comes back to your python website with a ?code or error message
you exchange the ?code for an access token/refresh token
Does this require Server side programming like Flak or such library?
Yes youâll need something âwebsiteyâ since youâll need to present a website for users to provide the initial access token for their account
Iâm using TWITCH API for some data collection and was thinking if I can do everything automatically by parsing and no manual efforts but looks like from what youâre saying some server side programming or âwebisteyâ would be required
Is that correct understanding?
if you are accessing public data then you can generate a âClient Credentialsâ token instead.
Which only needs a single post request.
Your original post was asking about how to get the ?code= from step 2
I reached maximum limit reply so couldnât reply
Iâm trying to get Twitch data from "Get Game Analytics - https://dev.twitch.tv/docs/api/reference/#get-game-analytics
Still I need to use Client-Credentials? In Client credentials Iâm able to do Post Command and retrieve Access Token but that access token cannot be used in âGet Game analyticsâ pipeline it then throws an error 401. -"Missing User Authentication "
This requires to you own a game on Twtich after having created an organistation and claimed a game.
This API endpoint will require a user access token
Yes iâm aware.
When you say User Access Token how can I get one?
We already covered this in this thread already