我正在尝试为 macOS 集成
Google Signin
。我使用 Swift
和 AppKit Cocoa
创建了一个本机 macOS 应用程序
在我的 info.plist 中添加了以下代码
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.MY_IDENTIFIER</string>
</array>
</dict>
</array>
<key>GIDClientID</key>
<string>MY_IDENTIFIER.apps.googleusercontent.com</string>
<key>GIDServerClientID</key>
<string>MY_IDENTIFIER_TWO.apps.googleusercontent.com</string>
我的快速代码点击按钮即可进行 Google 登录
@objc func button1Clicked() {
if let window = view.window {
GIDSignIn.sharedInstance.signIn(withPresenting: window) { signInResult, error in
debugPrint("Error \(error)")
guard error == nil else { return }
guard let signInResult = signInResult else { return }
let user = signInResult.user
let emailAddress = user.profile?.email
let fullName = user.profile?.name
let givenName = user.profile?.givenName
let familyName = user.profile?.familyName
let profilePicUrl = user.profile?.imageURL(withDimension: 320)
// If sign in succeeded, display the app's main content View.
}
}
}
我收到错误消息
”
Error Optional(Error Domain=org.openid.appauth.oauth_token Code=-2 \"invalid_request: client_secret is missing.\" UserInfo={OIDOAuthErrorResponseErrorKey={\n error = \"invalid_request\";\n \"error_description\" = \"client_secret is missing.\";\n}, NSLocalizedDescription=invalid_request: client_secret is missing., NSUnderlyingError=0x600002973660 {Error Domain=org.openid.appauth.remote-http Code=400 \"{\n \"error\": \"invalid_request\",\n \"error_description\": \"client_secret is missing.\"\n}\" UserInfo={NSLocalizedDescription={\n \"error\": \"invalid_request\",\n \"error_description\": \"client_secret is missing.\"\n}}}})"
我还为 Web 应用程序创建了客户端 ID
桌面客户端 ID
请确保 Google Console 中的客户端类型设置为“iOS”。如果您不小心创建了桌面或Web应用程序,您将遇到此错误。 iOS 选项