1

I am stuck on this API thing. I want to print the incoming json file (channel points in specific) but it just prints the whole page in html format. Here is my code:

import requests
import json

client_id = secret
oauth_token = secret

my_uri = 'https://localhost'

header = {"Authorization": f"Bearer {oauth_token}"}

url = f'https://id.twitch.tv/oauth2/authorize?client_id={client_id}&redirect_uri={my_uri}&response_type=id_token&scope=channel:read:redemptions+openid&state=c3ab8aa609ea11e793ae92361f002671&claims={"id_token":{"email_verified":null}}'

response = requests.get(url, headers=header)

print(response.text)

My hypothesis is that either the url or the header is the problem. The twitch API is made for c# or js originally but I don't know how to convert that information to python.

I would also like to know how to do the "PING" and "PONG" thing that Twitch is writing about in the API

Androtex
  • 31
  • 7

2 Answers2

0

response.text show the html text

response.json show the json

tell me if it work now

eyal
  • 107
  • 1
  • 7
  • The only response I get is `` which I think means that it is not an error. I therefore think that the problem is within the `url` or the `header`. – Androtex Dec 21 '20 at 22:33
  • if you print(response) you will get you need to print(response.json) – eyal Dec 21 '20 at 22:35
  • That is what I did, if I print `response.json` i get `` and the same when I print `response` alone. – Androtex Dec 21 '20 at 22:48
  • ther is no json you get html text so json does nothing cos you didnt have any json in the response – eyal Dec 21 '20 at 23:02
  • Then there is something wrong with the url or the header, because it should return a json file – Androtex Dec 21 '20 at 23:06
0

response.json() will return you the data in JSON format

Lemon.py
  • 819
  • 10
  • 22