MusicKit: developer token request failed

The MusicKit video states that you just enable "MusicKit" in your application identifier and "you're done!"

Ok, so I did that, and I'm seeing the following error when trying to run a song query:

[DataRequesting] Failed retrieving MusicKit tokens: Error Domain=ICErrorDomain Code=-8200 "Media API Token Service's response was invalid (status code: Unauthorized (401))." UserInfo={NSDebugDescription=Media API Token Service's response was invalid (status code: Unauthorized (401))., NSUnderlyingError=0x6000023a0c60 {Error Domain=AMSErrorDomain Code=301 "Invalid Status Code" UserInfo={NSLocalizedDescription=Invalid Status Code, AMSURL=https://sf-api-token-service.itunes.apple.com/apiToken?REDACTED, AMSStatusCode=401, AMSServerPayload={
    status = verificationFailure;
}, NSLocalizedFailureReason=The response has an invalid status code}}}. Throwing .developerTokenRequestFailed.

Is this just broken on Apple's side? Is there some other magic string that needs to be added to the plist other than NSAppleMusicUsageDescription?

Hello @xinsight,

Thank you for letting us know about this error you're encountering while running a song query.

We would definitely like to investigate this further, but to do that, we need to get a sysdiagnose from your device. Would you mind creating a new ticket on Feedback Assistant about this issue, including a sysdiagnose?

Thank you very much in advance for your help.

Best regards,

Hello @xinsight,

Thank you very much for filing this Feedback Assistant ticket.

It seems to me like you were trying to use MusicKit from the iOS simulator. Unfortunately, this functionality requires running on an actual device, as outlined in our release notes:

MusicKit functionality, such as loading content with music requests, doesn’t work in simulated devices.

I’ll use your ticket to track a change aimed at improving the error message produced for simulators.

I hope this helps.

Best regards,

Hello @JoeKun, I get the same error on a device in an app I uploaded on TestFlight. Is there anything I can do to debug it?

At the moment I don't have any device with iOS 15, nor macOS 12.

Thanks. Best regards,

Hello @gianpierospi,

I'm happy to hear that your momentary issue with MusicKit is now resolved. If you ever encounter this again, please try to grab a sysdiagnose from the device that can reproduce the issue, and then file a ticket on Feedback Assistant including that sysdiagnose.

I hope this helps.

Best regards,

I tried running my app on an iOS 15 device. I now get a user token request failure.

I am calling MusicKit.MusicAuthorization.request() which triggers an alert, and once accepted the result is .authorized I run the search.

        let request = MusicCatalogSearchRequest(term: "hello", types: [Song.self])
        do {
            let response = try await request.response()
            searchResults = Array(response.songs)
            print("RESPONSE: \(response)")
        } catch let error {
            NSLog("error: \(error)")
        }

The full error is:

[DataRequesting] Failed retrieving MusicKit tokens: Error Domain=ICErrorDomain Code=-8102 "Failed to fetch user token." UserInfo={NSDebugDescription=Failed to fetch user token., NSUnderlyingError=0x281932670 {Error Domain=ICErrorDomain Code=-7007 "Not getting music user token because privacy acknowledgement is required." UserInfo={NSDebugDescription=Not getting music user token because privacy acknowledgement is required.}}}. Throwing .userTokenRequestFailed.
2021-06-17 19:53:23.743941-0400 Radio[588:41570] [DataRequesting] Failed retrieving tokens for MusicDataRequest.Context(url: https://api.music.apple.com/v1/catalog/ca/search?term=hello&types=songs&omit%5Bresource%5D=autos). Error = .userTokenRequestFailed.

I have the plist values kTCCServiceMediaLibrary and NSAppleMusicUsageDescription set, but I'm not sure what "Not getting music user token because privacy acknowledgement is required." is referring to. Any ideas?

Hello @xinsight,

This means your user needs to acknowledge the latest privacy policy for Apple Music in the Music app.

Once your user has acknowledged the latest privacy policy for Apple Music, then this should work.

That said, it's unfortunate that we'd be returning .userTokenRequestFailed. Instead, I think we should be returning .privacyAcknowledgementRequired.

We'll see if we can improve the error returned to use the correct value.

I hope this helps.

Best regards,

I'm working with MusicKit right now, and found that while API calls fail in an iOS 15 simulator, they work in an iOS 16 one. Search queries do, at least.

MusicKit: developer token request failed
 
 
Q