我最近偶然发现了一些关于非官方 Pandora API 的文档。
我决定用 Python 3 试试这个。
在前往身份验证页面后,我看到我首先必须验证该服务在我的国家/地区是否可用,所以我这样做了。
import requests
import urllib
url = "http://internal-tuner.pandora.com/services/json/?method=test.checkLicensing"
res = requests.post(url)
print(res.status_code)
print(res.content)
它打印出来:
<Response [200]>
b'{"stat":"ok","result":{"isAllowed":true}}'
对。所以我被允许使用合作伙伴服务。
接下来我看到我必须获得一个Partner Login。
所以我从合作伙伴页面得到了它说我需要的信息。
请注意,这不是我的登录信息。这是我被告知在文档中选择的合作伙伴信息。
username = "android"
password = "AC7IBG09A3DTSYM4R41UJWL07VLN8JI7"
deviceModel = "android-generic"
接下来,文档说将发布请求发送到以下链接之一作为基本url:
- http://tuner.pandora.com/services/json/
- https://tuner.pandora.com/services/json/
- http://internal-tuner.pandora.com/services/json/
- https://internal-tuner.pandora.com/services/json/
现在对 url 参数进行编码并将它们放在基本 url 之后。它说我应该采用上面的username
, password
, deviceModel
,我想调用的方法(对于合作伙伴登录,它说它是“auth.PartnerLogin”,以及版本(它说传入字符串“5”)和 url 对它们进行编码。
所以我以 urlencoded 格式设置 url 参数并触发 POST 请求:
import requests
import urllib
url = "http://internal-tuner.pandora.com/services/json/?"
username = "android"
password = "AC7IBG09A3DTSYM4R41UJWL07VLN8JI7"
deviceModel = "android-generic"
data = {
"method": "auth.partnerLogin",
"username": username,
"password": password,
"deviceModel": deviceModel,
"version": "5"
}
url += urllib.parse.urlencode(data)
res = requests.post(url)
print("url:", url)
print("response:", res)
print("content:", res.content)
但是当我这样做时,它会打印出来并告诉我有一个错误:
url: http://internal-tuner.pandora.com/services/json/?method=auth.partnerLogin&username=android&password=AC7IBG09A3DTSYM4R41UJWL07VLN8JI7&deviceModel=android-generic&version=5
response: <Response [200]>
content: b'{"stat":"fail","message":"An unexpected error occurred","code":9}'
有其他人以前使用过这个 Api 吗?为什么我会收到错误消息?我在这里错过了什么吗?显然pithos使用了这个api,它对我来说加载音乐很好。
有人可以在这里指出我正确的方向吗?