MusicKit Issues getting UserToken

Hi there,

I'm currently experimenting with the `Adding-Content-to-Apple-Music` code found here: https://developer.apple.com/musickit/


I'm using:

XCode 9 beta 2

iOS 11 (iPhone 5s)


Other factors:
- my test code has the same bundle identifier as in the 'Music ID' set up over on developer.apple.com

- I am not US based (there has been some talk of this API having a geo-based lock down on it maybe?


I have a developer token (which works when I query the Apple Music API searching songs etc...) but I now want to use this to exchange for a User Token so I can perform write actions against my Apple Music account.


The test app fires up and allows me to request authentication. From this I can see:


MPMedia Library - Authorized

SKCloudServicesController - Authorized

Capabilities:

- Add to Cloud Music Library

- Music Catalog Playback


My next obvious step is to use the developer token to gain the user token. However, as soon as I call the following:


cloudServiceController.requestUserToken(forDeveloperToken: developerToken, completionHandler: completionHandler)


i see the following error in the `completionHandler` - can anyone help?


2017-07-14 10:05:39.179300+0100 Adding-Content-to-Apple-Music[1326:172100] [MC] Reading from public effective user settings.
2017-07-14 10:05:40.635503+0100 Adding-Content-to-Apple-Music[1326:172299] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2017-07-14 10:05:40.636449+0100 Adding-Content-to-Apple-Music[1326:172100] SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
2017-07-14 10:05:40.800933+0100 Adding-Content-to-Apple-Music[1326:172297] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2017-07-14 10:05:40.801259+0100 Adding-Content-to-Apple-Music[1326:172299] SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
An error occurred when requesting user token: The operation couldn’t be completed. (SKErrorDomain error 1.)


When I rerun I also get:


An error occurred when requesting user token: The operation couldn’t be completed. (SKErrorDomain error 7.)
Answered by scgough in 250125022

Update - this was an issue Apple side and it is seemingly now fixed. I can get a usertoken (in iOS 10 as well).

Check my solution at the bottom of this thread.


https://forums.developer.apple.com/message/245852#245852

Hi

Thanks for that. I've been able to get search to work too using a similar method of forcing the country code. The search only uses the `Developer Token`, not the `User Token`.


I think the way this sample app should work is to obtain the `User Token` then get the country code. Because it never gets the user token it in turn never carries on to get the country code.


The issue for me is that although I can search, I can't in fact add anything from the search to a playlist and when I click 'recents' I'm presented with a `User Token` error.

.

Accepted Answer

Update - this was an issue Apple side and it is seemingly now fixed. I can get a usertoken (in iOS 10 as well).

How are you able to get a user token in iOS 10? XCode doesn't allow me to use the requestUserToken method without checking for iOS 11.


XCode (9 beta 5) returns this error: 'requestUserToken(forDeveloperToken:completionHandler:)' is only available on iOS 11.0 or newer

still not getting the user token. experimenting with other features but would be nice to have one 😟

I'm also not getting the user token. Same output as the OPs; I see my accounts showing "Authorized", but no user token. I've tried on iOS 9, 10, and 11 on 3 different devices (iPhone 5s, iPad Pro, and iPhone 7) and I'm getting the same SKErrorDomain error 7 response. Any updates on this issue?

Update: For anyone coming here from Google, you may also get this error is your developer key is improperly encoded.


To fix this, download this: https://github.com/pelauimagineering/apple-music-token-generator

Update with your information and run from the command line. This will give you the developerAuthenticationToken string that you'll input into the sample. Keep in mind that the key expires no more than 6 months from when you create it so you'll need to be able to retreive it from somewhere that can be updated without resubmitting to App Store.

thanks a lot man!

Any update? Won't work for me.

Please stop sharing this: https://github.com/pelauimagineering/apple-music-token-generator This is NOT generating the music token, but the developer token. The whole thing is misleading and wrong

MusicKit Issues getting UserToken
 
 
Q