首页 > 解决方案 > 请求musickitusertoken时无法识别问题,curl请求也不起作用

问题描述

使用 Music Kit 请求用户令牌时出现此错误:

错误域=SKErrorDomain Code=7 "(null)" UserInfo={NSUnderlyingError=0x281e94a20 {错误域=SSErrorDomain Code=109 "(null)" UserInfo={NSUnderlyingError=0x281e965e0 {错误域=SSErrorDomain Code=109"无法连接到 iTunes Store" UserInfo={NSLocalizedDescription=无法连接到 iTunes Store, SSErrorHTTPStatusCodeKey=401}}}}}

使用正确代码发送 curl 请求时,我也收到 401 错误:

curl -v -H 'Authorization: Bearer [developer token]' "https://api.music.apple.com/v1/catalog/us/songs/203709340"

我无休止地四处寻找,找不到解决方案。我已经尝试过多次更改开发令牌,所以我很确定这不是问题。这是我的代码:

    SKCloudServiceController.requestAuthorization { (status) in
        if status == .authorized {
                self.cloudServiceController.requestStorefrontCountryCode(completionHandler: { (response, error) in
                    if error == nil {
                        UserDefaults.standard.set(response!, forKey: "MusicKitCountryCode")
                        print("Country code")
                        print(response)
                        self.cloudServiceController.requestUserToken(forDeveloperToken: musicKitDevToken) { (responseString, error) in
                            if error == nil {

                                self.updateServiceTokens(token: responseString!)

                                print("should complete")
                                completion(true)
                            } else {
                                print("there was an error fetching user token: \(error!)")
                            }
                        }
                    } else {
                        print("error fetchin storefront country code: \(error!)")
                    }
                    
                })
            } else {
                print("cloud service controller not authorized`")
            }
        }

标签: iosswiftcurlapple-musickit

解决方案


推荐阅读