可能是因为缺少OAuth2令牌或API密钥。请确保您正确获得了这些凭据,并在API请求中正确使用它们。以下是一个使用OAuth2令牌进行API调用的示例Python代码:
import requests
import json
# Enter your OAuth2 token and API key here
oauth_token = "your_oauth_token"
api_key = "your_api_key"
# Define the API endpoint and parameters
endpoint = "https://www.bungie.net/platform/Destiny2/SearchDestinyPlayer/-1/{}/".format("your_gamertag")
headers = {"X-API-Key": api_key, "Authorization": "Bearer " + oauth_token}
params = {"membershipType": 1}
# Make the API call
response = requests.get(endpoint, headers=headers, params=params)
response_body = json.loads(response.text)
# Print the response body
print(response_body)
请确保您已在代码中正确替换上述代码示例中用于OAuth2令牌、API密钥和游戏标识符的占位符(你的游戏账号名)和正确的参数。