gpt4 book ai didi

ios - Google OAuth 2.0 invalid_client 未经授权

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

我使用此代码通过 OAuth 2.0 授权 Google+

oauthswift = OAuth2Swift( consumerKey: "984813079630-f828a92sqtl5lgumd4kgp9i30bs9og09.apps.googleusercontent.com", consumerSecret: "AIzaSyD13MBv78yWIjl4TX9jOOT9AWuEkYdVSPQ", authorizeUrl: "https://accounts.google.com/o/oauth2/v2/auth", accessTokenUrl: "https://www.googleapis.com/oauth2/v4/token", responseType: "code" )

    let handle = oauthswift.authorize(
withCallbackURL: URL(string: "com.googleusercontent.apps.984813079630-f828a92sqtl5lgumd4kgp9i30bs9og09:/oauth")!,
scope: "profile", state:"GOOGLE",
success: { credential, response, parameters in
print(credential.oauthToken)
// Do your request
},
failure: { error in
print(error.localizedDescription)
print((error as OAuthSwiftError).errorUserInfo)
}
)

但结果总是失败

The operation couldn’t be completed. (OAuthSwiftError error -11.) ["request": https://www.googleapis.com/oauth2/v4/token, "error": Error Domain=NSURLErrorDomain Code=401 "invalid_client Unauthorized" UserInfo={Response-Body={ "error": "invalid_client", "error_description": "Unauthorized" } , NSErrorFailingURLKey=https://www.googleapis.com/oauth2/v4/token, Response-Headers={ "Cache-Control" = "private, max-age=0"; "Content-Encoding" = gzip; "Content-Length" = 81; "Content-Type" = "application/json; charset=UTF-8"; Date = "Thu, 15 Jun 2017 04:25:10 GMT"; Expires = "Thu, 15 Jun 2017 04:25:10 GMT"; Server = GSE; Vary = "Origin, X-Origin"; "Www-Authenticate" = "Bearer realm=\"https://accounts.google.com/\""; "alt-svc" = "quic=\":443\"; ma=2592000; v=\"38,37,36,35\""; "x-content-type-options" = nosniff; "x-frame-options" = SAMEORIGIN; "x-xss-protection" = "1; mode=block"; }, OAuthSwiftError.response= { URL: https://www.googleapis.com/oauth2/v4/token } { status code: 401, headers { "Cache-Control" = "private, max-age=0"; "Content-Encoding" = gzip; "Content-Length" = 81; "Content-Type" = "application/json; charset=UTF-8"; Date = "Thu, 15 Jun 2017 04:25:10 GMT"; Expires = "Thu, 15 Jun 2017 04:25:10 GMT"; Server = GSE; Vary = "Origin, X-Origin"; "Www-Authenticate" = "Bearer realm=\"https://accounts.google.com/\""; "alt-svc" = "quic=\":443\"; ma=2592000; v=\"38,37,36,35\""; "x-content-type-options" = nosniff; "x-frame-options" = SAMEORIGIN; "x-xss-protection" = "1; mode=block"; } }, OAuthSwiftError.response.data=<7b0a2022 6572726f 72223a20 22696e76 616c6964 5f636c69 656e7422 2c0a2022 6572726f 725f6465 73637269 7074696f 6e223a20 22556e61 7574686f 72697a65 64220a7d 0a>, NSLocalizedDescription=invalid_client Unauthorized}]

你能改正一下吗?

最佳答案

您必须删除替换 withCallbackURL "com.googleusercontent.apps.984813079630-f828a92sqtl5lgumd4kgp9i30bs9og09:/oauth""your.bundle.id:/oauth2Callback"

来自演示 OAuthSwift 的评论:

For googgle the redirect_uri should match your this syntax: your.bundle.id:/oauth2Callback

In plist define a url schem with: your.bundle.id

经过这些更改后,我仍然遇到这个问题。找到解决方案:

然后我用一个空字符串删除了 customerSecret。它起作用了。

以上的回答希望对您有所帮助!

关于ios - Google OAuth 2.0 invalid_client 未经授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44558561/

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