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,

Replies

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

It won't work on iOS 10 as it is a new API for iOS 11: https://developer.apple.com/documentation/storekit/skcloudservicecontroller/2909079-requestusertoken