我正在尝试访问Apple Music API的API
(https://developer.apple.com/documentation/applemusicapi)。
创建JWT开发人员令牌后,当我尝试访问API时,发生401 - Unauthorized
错误。
我通过以下方式进行操作:
注册新的音乐标识符(https://help.apple.com/developer-account/#/devce5522674?sub=dev0416b9004)
创建MusicKit标识符和私钥(https://help.apple.com/developer-account/#/devce5522674)也会下载私钥文件。
获取孩子(密钥ID)和发行者(团队ID)。
运行以下代码以生成令牌:
const jwt = require("jsonwebtoken");
const privateKey = fs.readFileSync("AuthKey_KEY_ID.p8").toString();
const teamId = TEAM_ID_HERE;
const keyId = KEY_ID_HERE;
const jwtToken = jwt.sign({}, privateKey, {
algorithm: "ES256",
expiresIn: "120d",
issuer: teamId,
header: {
alg: "ES256",
kid: keyId
}
});
console.log(jwtToken);```
And after that checking the code using the curl command :
```curl -v -H 'Authorization: Bearer [developer token]' "https://api.music.apple.com/v1/catalog/us/songs/203709340"```
I am not sure what i am missing here. is it something related to access or is it my code.
P.S : I am the Account Holder, so it is not an issue related to role.
Thanks