401-生成开发人员令牌后,Apple Music API中出现未经授权的错误

时间:2019-05-14 09:54:06

标签: ios node.js apple-music apple-musickit

我正在尝试访问Apple Music API的API

https://developer.apple.com/documentation/applemusicapi)。

创建JWT开发人员令牌后,当我尝试访问API时,发生401 - Unauthorized错误。

我通过以下方式进行操作:

  1. 注册新的音乐标识符(https://help.apple.com/developer-account/#/devce5522674?sub=dev0416b9004

  2. 创建MusicKit标识符和私钥(https://help.apple.com/developer-account/#/devce5522674)也会下载私钥文件。

  3. 获取孩子(密钥ID)和发行者(团队ID)。

  4. 运行以下代码以生成令牌:

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

0 个答案:

没有答案