How to Create a Apple Music User Token outside iOS

2019-04-12 17:50发布

I am trying to let people like tracks, albums or playlists on Apple Music from a webpage.

I understand the manual on this page: https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/AppleMusicWebServicesReference/SetUpWebServices.html

Until I hit the part where I should use the requestUserToken(forDeveloperToken:completionHandler:) method from SKCloudServiceController in the StoreKit framework, since there is no StoreKit framework available for outside iOS.

How is this token generated? Is there any other way I can generate this Music User Token manually?

I know it is a (very) longshot, but maybe someone figured it out!

3条回答
仙女界的扛把子
2楼-- · 2019-04-12 18:21

The new Apple MusicKit JS library allows you to create Music User Token's from your Developer Token as seen here outside of iOS. Once you've loaded the Library you can use the authorize method to allow a user to authenticate and generate a token.

document.addEventListener('musickitloaded', function() {
  // MusicKit global is now defined
  MusicKit.configure({
    developerToken: 'DEVELOPER-TOKEN',
    app: {
      name: 'My Cool Web App',
      build: '1978.4.1'
    }
  });

  let music = MusicKit.getInstance();

  music.authorize().then(musicUserToken => {
    console.log(musicUserToken);
  });
});
查看更多
ら.Afraid
3楼-- · 2019-04-12 18:33

I have tried the approach within my iOS app.

You can follow this link generate music token

This is basically python script. You can easily create a music developer token from your mac.

查看更多
萌系小妹纸
4楼-- · 2019-04-12 18:38

It’s not possible to obtain a user token from outside the iOS SDK. If you want to interact with a user’s Apple Music library you will need to do this on an iOS device using the StoreKit SDK.

However, you only need this token to interact with a user’s library. It is not needed for querying the Apple Music catalog APIs. For this you only need a developer token which can be generated from your certificate.

查看更多
登录 后发表回答