Streamlabs API v2.0 捐赠接口调用返回401未授权问题求助
Streamlabs API v2.0 捐赠接口调用返回401未授权问题求助
我最近在做第三方捐赠服务和Streamlabs的集成,想通过调用Streamlabs的捐赠接口,把外部的捐赠记录同步到Streamlabs后台里。照着思路写了Python代码,但折腾了两个小时,不管怎么调试都一直收到401未授权的错误,实在找不到问题出在哪,来求助各位大佬!
我的代码如下:
import requests import datetime API_ACCESS_TOKEN = "MY API ACCESS TOKEN" # FROM https://streamlabs.com/dashboard#/settings/api-settings url = "https://streamlabs.com/api/v2.0/donations" headers = { "accept": "application/json", "Authorization": f"Bearer {API_ACCESS_TOKEN}", "Content-Type": "application/json" } # Donation data (replace with actual values) donation_data = { "name": "John Doe", "message": "Thanks for the stream!", "identifier": "john.doe@example.com", "amount": 10.00, "currency": "USD", "created_at": datetime.datetime.now().isoformat(), } if __name__ == '__main__': response = requests.post(url, headers=headers, json=donation_data) if response.status_code == 200: print("Donation created successfully!") print(response.text) elif response.status_code == 400: print("Error creating donation:") print(response.text) else: print(f"Unexpected status code: {response.status_code}") print(response.text)
运行后得到的错误信息是:
Unexpected status code: 401 Unauthorized.
我已经确认过API访问令牌是从Streamlabs后台的API设置页面获取的,但就是一直报未授权,有没有朋友遇到过类似的问题,或者能帮我看看代码里哪里有问题吗?
备注:内容来源于stack exchange,提问作者ThunderHorn
相关产品推荐
相关产品推荐

