1

我正在尝试访问 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. 获取 Kid (Key Id) 和 issuer (Team 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
4

0 回答 0