gpt4 book ai didi

ios - 如何正确登录到 spotify?

转载 作者:搜寻专家 更新时间:2023-11-01 05:40:22 24 4
gpt4 key购买 nike

我有一个应用程序允许用户从 spotify 流式传输歌曲。我这里用的是swift。我试图让用户使用 spotify 帐户登录,但我没有得到任何返回。我的应用程序确实打开了 safari 以打开 spotify 登录页面。我已完成登录,但仍未返回任何内容。

我已确保我的callbackuri 与我的 spotify 开发页面中的完全相同,我的 url 方案是我的回调 uri 冒号之前的第一部分,我的其他链接器充满了 < strong>-ObjC

这是我试过的

登录操作:

    let spotifyAuth = SPTAuth.defaultInstance()
spotifyAuth.clientID = kSpotifyClientID
spotifyAuth.redirectURL = NSURL(string: kSpotifyCallBackUrl)
spotifyAuth.requestedScopes = [SPTAuthStreamingScope]

let spotifyLoginUrl : NSURL = spotifyAuth.loginURL

UIApplication.sharedApplication().openURL(spotifyLoginUrl)

我的应用代理:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool{

println("rene jos1")
if (SPTAuth.defaultInstance().canHandleURL(url)) {


println("rene jos2")

SPTAuth.defaultInstance().handleAuthCallbackWithTriggeredAuthURL(url, callback: { (error : NSError?, session : SPTSession?) -> Void in


println("rene jos3")
if error != nil {

println("Auth error : \(url.description)")
return
}

let userDefaults = NSUserDefaults.standardUserDefaults()
let sessionData = NSKeyedArchiver.archivedDataWithRootObject(session!)
userDefaults.setObject(sessionData, forKey: "spotifySession")

userDefaults.synchronize()

NSNotificationCenter.defaultCenter().postNotificationName("spotifyLoginSuccesfull", object: nil)

})

return true
}

if (FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)) {

return true
}

return false
}

和我的viewdidload:

 NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateAfterFirstlogin", name: "spotifyLoginSuccesfull", object: nil)
// Do any additional setup after loading the view.
spotifyLoginButton.hidden = true

let userDefaults = NSUserDefaults.standardUserDefaults()

if let sessionObj : AnyObject = NSUserDefaults.standardUserDefaults().objectForKey("spotifySession") {
println("rene 2")

let sessionDataObj : NSData = sessionObj as! NSData
let session = NSKeyedUnarchiver.unarchiveObjectWithData(sessionDataObj) as! SPTSession
self.playUsingSession(session)

if !session.isValid() {

SPTAuth.defaultInstance().renewSession(session, callback: { (error : NSError!, newsession : SPTSession!) -> Void in

let sessionData = NSKeyedArchiver.archivedDataWithRootObject(session)
userDefaults.setObject(sessionData, forKey: "spotifySession")
userDefaults.synchronize()

self.session = newsession

self.playUsingSession(newsession)
println("rene 3")
})
}else{

println("error refreshing new spotify session")

}

}else{

spotifyLoginButton.hidden = false
println("rene 4")

}

那么,我是不是漏掉了什么?任何建议都会很棒

最佳答案

确保你的回调 uri 都是小写字母,我对此有疑问。

关于ios - 如何正确登录到 spotify?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31337034/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com