我用这个代码通过OAuth 2.0谷歌的OAuth 2.0 invalid_client未经授权
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: “代码” )
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) } )
但结果总是失败
操作无法完成。 (OAuthSwiftError错误-11) [ “请求”:https://www.googleapis.com/oauth2/v4/token “错误”:错误 域= NSURLErrorDomain代码= 401 “invalid_client未授权” 的UserInfo = {响应式体= { “错误”: “invalid_client”, “ error_description“:”Unauthorized“}, NSErrorFailingURLKey = https://www.googleapis.com/oauth2/v4/token, Response-Headers = { ”Cache-Control“=”private,max-age = 0“; “内容编码”= gzip; “Content-Length”= 81; “Content-Type”=“application/json; charset = UTF-8”; 日期=“星期四,15六月2017 04:25:10 GMT”; Expires =“2017年6月15日星期四04:25:10 GMT”; Server = GSE; Vary =“Origin,X-Origin”; “Www-Authenticate”=“承载领域= \”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”; “内容编码”= gzip; “Content-Length”= 81; “Content-Type”=“application/json; charset = UTF-8”; 日期=“星期四,15六月2017 04:25:10 GMT”; Expires =“2017年6月15日星期四04:25:10 GMT”; Server = GSE; Vary =“Origin,X-Origin”; “Www-Authenticate”=“承载领域= \”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未经授权}]
请您更正?
你是对的! – haithngn
它的工作!你救了我的时间:) –