我用這個代碼通過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
它的工作!你救了我的時間:) –