Error Occurred when requesting user token (SKErrorDomain Code=7)

Trying to get the sample project to work (Adding Content to Apple Music). I've gotten a proper developer token and I can log in and see that I'm authorized by MPMediaLibrary and SKCloudServiceController. I also have both "Add to Cloud Music Library" and "Music Catalog Playback" capabilities.


When I try to return music data by clicking on the "Recents" tab, I get the error:


"No User Token was Specified. Request Authorization using the Authorization tab." I already have authorization in that tab as noted above.


From debugging, this is the code that errors out.


if SKCloudServiceController.authorizationStatus() == .authorized {

let completionHandler: (String?, Error?) -> Void = { [weak self] (token, error) in

guard error == nil else {

print("An error occurred when requesting user token: \(error!.localizedDescription)")

return

}


error.localizedDescription is SKErrorDomain Code = 7. From my searches, this seems to be a can't connect to the cloud error? Though I can't confirm that..


Any idea why I would show SKCloudService authorized in one tab but yet it still seems to error out?


Thanks for the help,

Hi

Just wondering - did you get past this error and obtain a UserToken? I too am having the same issue!

Hi,


I'm having the same error. The only thing I found is that the error code SKErrorDomain Code = 7 corresponds to cloudServiceNetworkConnectionFailed (https://developer.apple.com/documentation/storekit/skerror.code/1620611-cloudservicenetworkconnectionfai)

This doesn't help any of you, but I'm getting the same error.

I'm also getting

SSErrorHTTPStatusCodeKey=500

in the same response which feels like the backend isn't working at the moment.

Hi Westerlund / pballart,

It's frustrating isn't it! I do think it is working though as I've seen cases of users obtaining the user token and carrying out use-token context API calls.


I wondered if it was an issue with my Developer token but I know I can make successful API (read) calls with it (in c#) - searches, song/album lookups etc.


If I get a solution I will post it here. Could you both do the same please?


ps - Is there a parent page this this one listing all the enumeration definitions? I'd like to know what code `9` and `1` mean https://developer.apple.com/documentation/storekit/skerror.code/1620611-cloudservicenetworkconnectionfai


EDIT - I think I've found the enum translation for SKError here: https://developer.apple.com/documentation/storekit/skerror.code

Is there a chance the API is geo-blocked or limited by location right now? I don't know why else the "network can't connect" error would show other than me being outside the USA?

Could be... I'm also outside the US.

If I find anything I'll post it here.

FYI - I'm also outside the US.

I am getting the same error but I am inside the US


Edit: See solution below

Try this, I was able to get search to work.


I added:

        if cloudServiceStorefrontCountryCode == "" {
            requestStorefrontCountryCode()
        }


Above: (In AuthorizationManager.swift - requestUserToken())

        if SKCloudServiceController.authorizationStatus() == .authorized {


For some reason it looks like it is never trying to get your country code. That code was never getting hit for me. Need to look into why. There is probably a much better place to put this check, but its late and I am tired. Update me if you find a good place, or why its never getting called.

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.

Same issue. Running sample code and not getting the user token. Has anyone filed a bug report yet?

This worked to get past this, but on to another error. Within the performAppleMusicGetUserStoreFront function, I get a runtime error during the code:


let task = urlSession.dataTask(with: urlRequest) { [weak self] (data, response, error) in

guard error == nil, let urlResponse = response as? HTTPURLResponse, urlResponse.statusCode == 200 else {

let error = NSError(domain: "AppleMusicManagerErrorDomain", code: -9000, userInfo: [NSUnderlyingErrorKey: error!])


"Unexpectedly found nil while unwrapping an optional value".


This is testing on my iphone 7




Either the sample API code seems to have issues or the API network isn't fully up and running yet it appears.

Has anyone found a fix for this yet?


Also, is it necessary for me to use ios 11 to test this? Anyone managed to get it working on ios 10?

Yup, bug report filed at rdar://33586163

I have also experienced the same issue and filed a bug at rdar://33586163


I did have it working for a little while during beta 3 and was able to cache the token so I could work on my app. Unfortunately the cached token has now expired and now I can't authenticate again. Definitely seems like an issue on the server side as no code change within the same beta saw me get a token and get the SKErrorDomain 7.

Only the requestUserToken call requires iOS 11. The sample app already distinguishes between this with #available(ios 11) checks.


            if #available(iOS 11.0, *) {
                cloudServiceController.requestUserToken(forDeveloperToken: developerToken, completionHandler: completionHandler)
            } else {
                cloudServiceController.requestPersonalizationToken(forClientToken: developerToken, withCompletionHandler: completionHandler)
            }


Looking at the source code, I haven't figured out exactly what new APIs have been added for iOS 11 (that didn't already exist for iOS 10).

Same issue...

Running sample code and not getting the user token :/

Same issue. Not sure if this makes a difference for the priority this gets.

What's going on here. Same issue too.


Can we can an Apple response?

Is there a work around?

We are aware of the issue, and are testing a fix.

Thanks for the update 3ZS - appreciated.

Update - just to confirm, this is seemingly fixed now. I am receiving a usertoken in my test app on iOS 10.3 AND iOS 11.

Update - It's OK for me now too, I'm able to get a usertoken.

I'm getting this same problem. Still having issues?

Error Occurred when requesting user token (SKErrorDomain Code=7)
 
 
Q