gpt4 book ai didi

ios - 使用 p2.OAuth2 获取 soundcloud token

转载 作者:行者123 更新时间:2023-11-29 01:54:52 32 4
gpt4 key购买 nike

我正在尝试使用 p2/OAuth2 库成功检索 SoundCloud token - github:https://github.com/p2/OAuth2

基本上我使用 SoundCloud 属性重新创建了他在示例项目中提供的类

class SoundCloudLoader {

static var sharedInstance = SoundCloudLoader()

class func handleRedirectURL(url: NSURL) {
sharedInstance.oauth2.handleRedirectURL(url)
}

// MARK: - Instance

let baseURL = NSURL(string: "https://api.soundcloud.com")!

var oauth2 = OAuth2CodeGrant(settings: [
"client_id": "********", //copy/pasted from soundcloud
"client_secret": "********", //copy/pasted from soundcloud
"authorize_uri": "https://soundcloud.com/connect",
"token_uri": "https://api.soundcloud.com/oauth2/token",
"scope": "non-expiring",
"redirect_uris": ["myApp://oauth2"], // registered in info.plist and gets correctly called by AppDelegate
"keychain": false,
"verbose":true
])

/** Start the OAuth dance. */
func authorize(callback: (wasFailure: Bool, error: NSError?) -> Void) {
oauth2.afterAuthorizeOrFailure = callback
oauth2.authorize()
}
}

在 AppDelegate 中,我执行以下操作:

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

let backlink = url.absoluteString!

println(sourceApplication)

if sourceApplication == "com.apple.mobilesafari" || sourceApplication == "com.google.chrome.ios" {

if backlink.rangeOfString("myApp://oauth2") != nil {

SoundCloudLoader.handleRedirectURL(url)

}
}
}

考虑到日志文件,第一个请求似乎已成功完成,但在调用 token_uri 时中断了:

OAuth2: Initialized with client id XXX
OAuth2: No access token, maybe I can refresh
OAuth2: I don't have a refresh token, not trying to refresh
OAuth2: Authorizing against https://soundcloud.com/connect?client_id=XXX&redirect_uri=XXX&scope=non-expiring&response_type=code&state=xxx
Optional("com.apple.mobilesafari") //println of source App in AppDelegate Method
OAuth2: Handling redirect URL xxx?code=xxx&state=xxx#
OAuth2: Authorizing against https://api.soundcloud.com/oauth2/token?code=***&grant_type=authorization_code&client_id=xxx&redirect_uri=xxx&scope=non-expiring&state=xxx
OAuth2: Adding “Authorization” header as “Basic client-key:client-secret”
OAuth2: Exchanging code xxx with redirect xxx for access token at https://api.soundcloud.com/oauth2/token

OAuth2: Did not get access token expiration interval
OAuth2: Authorization error: invalid_client.
Error Domain=OAuth2ErrorDomain Code=605 "Authorization error: invalid_client." UserInfo=0x7f8aa05c6700 {NSLocalizedDescription=Authorization error: invalid_client.}

由于我是“OAuth 事物”的初学者,此日志文件是否暗示 lib 崩溃,因为 soundcloud 没有给出 token 的到期日期(在一些博客文章中,他们说他们当前正在使用未到期的 token ),还是因为 client-id 错误而突然崩溃? (它不是,因为它是 soundcloud-dev 后端中的那个,并且它能够获得请求代码)。

如有任何提示,我们将不胜感激。

最佳答案

尝试添加

oauth2.secretInBody = true

我遇到了同样的问题,这对我来说是个窍门。

关于ios - 使用 p2.OAuth2 获取 soundcloud token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30981082/

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