pre-oauthlib progress
This commit is contained in:
parent
a5312a4625
commit
7c95d3dd7b
40
example.py
40
example.py
@ -1,16 +1,42 @@
|
||||
from blizzardapi2 import BlizzardApi
|
||||
import requests
|
||||
import webbrowser
|
||||
|
||||
api_client = BlizzardApi("a79bae348867427690ca6df9903e4af0", "8l1KhVr1DkcqpXQl454WZmtlN3LvgBO5")
|
||||
CLIENTID = "a79bae348867427690ca6df9903e4af0"
|
||||
CLIENTSECRET = "VfFc4JRxn4MpA5zRVut1gPIh6E5WrEC5"
|
||||
OAUTH_TOKEN = "USCdfWcbxv1hGYQDPWSXbvr84SHme9eJ5T"
|
||||
REGION = "us"
|
||||
LOCALE = "en_US"
|
||||
|
||||
api_client = BlizzardApi(CLIENTID, CLIENTSECRET)
|
||||
|
||||
|
||||
# def create_access_token(client_id, client_secret, region = 'us'):
|
||||
# data = { 'grant_type': 'client_credentials' }
|
||||
# response = requests.post('https://%s.battle.net/oauth/token' % region, data=data, auth=(client_id, client_secret))
|
||||
# return response.json()
|
||||
#
|
||||
# response = create_access_token(CLIENTID, CLIENTSECRET)
|
||||
# print(response)
|
||||
|
||||
# Unprotected API endpoint
|
||||
categories_index = api_client.wow.game_data.get_achievement_categories_index("us", "en_US")
|
||||
# categories_index = api_client.wow.game_data.get_achievement_categories_index("us", "en_US")
|
||||
# print(categories_index)
|
||||
|
||||
# Protected API endpoint
|
||||
# summary = api_client.wow.profile.get_account_profile_summary("us", "en_US", "access_token")
|
||||
# summary = api_client.wow.profile.get_account_profile_summary(REGION, LOCALE, OAUTH_TOKEN)
|
||||
# print(summary)
|
||||
|
||||
# Wow Classic endpoint
|
||||
connected_realms_index = api_client.wow.game_data.get_connected_realms_index("us", "en_US", is_classic=True)
|
||||
# connected_realms_index = api_client.wow.game_data.get_connected_realms_index("us", "en_US", is_classic=True)
|
||||
# print(connected_realms_index)
|
||||
|
||||
print(categories_index)
|
||||
# print(summary)
|
||||
print(connected_realms_index)
|
||||
# def get_character_profile(realm, character):
|
||||
# profile_info = api_client.wow.profile.get_character_profile_summary(REGION, LOCALE, realm, character)
|
||||
# return profile_info
|
||||
#
|
||||
# character_faction = get_character_profile("area-52", "izyrra")["faction"]["name"]
|
||||
#
|
||||
# print(character_faction)
|
||||
|
||||
webbrowser.register('floorp').open_new_tab("https://bbc.co.uk")
|
||||
|
28
oauth-test.py
Normal file
28
oauth-test.py
Normal file
@ -0,0 +1,28 @@
|
||||
import requests
|
||||
from http.server import *
|
||||
import urllib.parse
|
||||
import webbrowser
|
||||
|
||||
CLIENTID = "a79bae348867427690ca6df9903e4af0"
|
||||
AUTH_URL = "https://oauth.battle.net/authorize"
|
||||
|
||||
# replace with your own http handlers
|
||||
def wait_for_request(server_class=HTTPServer,
|
||||
handler_class=BaseHTTPRequestHandler):
|
||||
server_address = ('', 5635)
|
||||
httpd = server_class(server_address, handler_class)
|
||||
return httpd.handle_request()
|
||||
|
||||
def authenticate():
|
||||
scope = "openid"
|
||||
redirect_uri = 'http://localhost:5635/login_success'
|
||||
params = {'client_id': CLIENTID, 'scope': scope, 'response_type': 'code',
|
||||
'state': "AbCdEfG", 'redirect_uri': redirect_uri}
|
||||
url = "{}?{}".format(AUTH_URL, urllib.parse.urlencode(params))
|
||||
webbrowser.open(url)
|
||||
response = wait_for_request()
|
||||
print(response)
|
||||
|
||||
authenticate()
|
||||
|
||||
# webbrowser.open_new_tab("https://oauth.battle.net/authorize?response_type=code&scope=openid&state=AbCdEfG&redirect_uri=http://localhost&client_id=" + CLIENTID)
|
9
testing.sh
Normal file
9
testing.sh
Normal file
@ -0,0 +1,9 @@
|
||||
CLIENT_ID="a79bae348867427690ca6df9903e4af0"
|
||||
CLIENT_SECRET="VfFc4JRxn4MpA5zRVut1gPIh6E5WrEC5"
|
||||
CLIENT_ACCESS_TOKEN_RESPONSE="$(curl -u $CLIENT_ID:$CLIENT_SECRET -d grant_type=client_credentials https://oauth.battle.net/token)"
|
||||
CLIENT_ACCESS_TOKEN=$(echo $CLIENT_ACCESS_TOKEN_RESPONSE | jq -r '.access_token')
|
||||
OAUTH_ACCESS_TOKEN_RESPONSE="$(curl -X POST https://oauth.battle.net/token -u $CLIENT_ID:$CLIENT_SECRET -d http://localhost -d grant_type=authorization_code -d code=$CLIENT_ACCESS_TOKEN)"
|
||||
OAUTH_ACCESS_TOKEN=$(echo $OAUTH_ACCESS_TOKEN_RESPONSE | jq -r '.access_token')
|
||||
echo $OAUTH_ACCESS_TOKEN_RESPONSE
|
||||
# curl -H "Authorization: Bearer $CLIENT_ACCESS_TOKEN" "https://us.api.blizzard.com/data/wow/token/?namespace=dynamic-us" | jq
|
||||
# curl -H "Authorization: Bearer $CLIENT_ACCESS_TOKEN" "https://us.api.blizzard.com/data/wow/guild/proudmoore/stellar/roster?namespace=profile-us" | jq '.members[].character.name'
|
1
toons-avglvl.sh
Normal file
1
toons-avglvl.sh
Normal file
@ -0,0 +1 @@
|
||||
curl -sH "Authorization: Bearer USCdfWcbxv1hGYQDPWSXbvr84SHme9eJ5T" "https://us.api.blizzard.com/profile/user/wow?namespace=profile-us&locale=en_US" | jq -r '[ .wow_accounts[0].characters[].level | select(.) ] | add / length'
|
1
toons-csv.sh
Normal file
1
toons-csv.sh
Normal file
@ -0,0 +1 @@
|
||||
curl -H "Authorization: Bearer USCdfWcbxv1hGYQDPWSXbvr84SHme9eJ5T" "https://us.api.blizzard.com/profile/user/wow?namespace=profile-us&locale=en_US" | jq -r '.wow_accounts[0].characters[] | [.name, .level] | @csv'
|
Loading…
Reference in New Issue
Block a user