gpt4 book ai didi

ios - 无法使用 Spotify iOS 9 登录

转载 作者:行者123 更新时间:2023-11-28 11:11:54 27 4
gpt4 key购买 nike

我无法使用 ios sdk spotify 登录。

我遵循了 Brian 的教程 (https://www.youtube.com/watch?v=GeO00YdJ3cE),但与当前的 spotify 教程有所不同:

在视频中,它讨论了 token 交换并显示了一个 spotify 网页。然而,在当前的 spotify 网页上,该段落丢失了。

是否必须安装此交换 token ?

我在我的 spotify 应用程序帐户中定义了所有元素。我还在 URL 方案中定义:“spotify-action”、“my-app-Name”,但我无法成功登录。

有人帮忙吗?

最佳答案

有两种选择:1) 隐式授予流程 - 授予用户访问 token ,将在 60 分钟后过期 - 它更简单,但如果你想构建一个可用的应用程序,它有限制。我会给你一个简单的例子,使用 spotify 的更新 sdk 框架(你不必使用 safari)..

class ViewController: UIViewController, SPTAuthViewDelegate {
let kclientID = ""
let kcallbackURL = ""

@IBAction func loginSpotify(sender: AnyObject){
SPTAuth.defaultInstance().clientID = kclientID
SPTAuth.defaultInstance().redirectURL = NSURL(string: kcallbackURL)
SPTAuth.defaultInstance().requestedScopes = [SPTAuthStreamingScope]
SPTAuth.defaultInstance().sessionUserDefaultsKey = "SpotifySession"
SPTAuth.defaultInstance().tokenSwapURL = NSURL(string: ktokenSwapURL) //you will not need this initially, unless you want to refresh tokens
SPTAuth.defaultInstance().tokenRefreshURL = NSURL(string: ktokenRefreshServiceURL)//you will not need this unless you want to refresh tokens

spotifyAuthViewController = SPTAuthViewController.authenticationViewController()
spotifyAuthViewController.delegate = self
spotifyAuthViewController.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
spotifyAuthViewController.definesPresentationContext = true
presentViewController(spotifyAuthViewController, animated: false, completion: nil)

}


func authenticationViewController(authenticationViewController: SPTAuthViewController!, didLoginWithSession session: SPTSession!) {
print("Logged In")
}

func authenticationViewController(authenticationViewController: SPTAuthViewController!, didFailToLogin error: NSError!) {
print("Failed to Log In")
print(error)
authenticationViewController.clearCookies(nil)
}

func authenticationViewControllerDidCancelLogin(authenticationViewController: SPTAuthViewController!) {
print("User Canceled Log In")
authenticationViewController.clearCookies(nil)
}
}

2) 授权代码流 - Spotify 的身份验证服务器发送您存储的加密刷新 token ,例如,

SPTAuth.defaultInstance().sessionUserDefaultsKey = "SpotifySession"。当该 session 过期时,您必须在服务器上触发一个功能...希望这可以帮助您入门

关于ios - 无法使用 Spotify iOS 9 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34465283/

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