我对编码相当陌生,但我正在尝试一个从暴雪api中提取一些数据的机器人。我拥有的bot运行良好,但每次访问令牌更改时,我都必须进入并手动更改json数据的url。我知道令牌每24小时都会更改一次,但我无法想象开发人员每天都要不断地到控制台上用更新的访问令牌调出新的url。我一直在浏览暴雪OAuth文档,发现有人为python发布了以下代码:
import requests
import json
from requests.auth import HTTPBasicAuth
def create_access_token(client_id, client_secret, region = 'us'):
url = "https://%s.battle.net/oauth/token" % region
body = {"grant_type": 'client_credentials'}
auth = HTTPBasicAuth(client_id, client_secret)
response = requests.post(url, data=body, auth=auth)
return response.json()
create_access_token()
但是当我把我的客户id和客户机密传递给这个时,我没有得到任何信息。任何帮助都会很棒。谢谢
您可以使用类似this的在线CURL to Python Requests ansible工具,从client credential flow的文档CURL示例中获取正确的请求格式:
卷曲
Python
相关问题 更多 >
编程相关推荐