Я выполнил все шаги Oauth и успешно получил токен доступа и другую информацию.
Но когда я вызываю api через этот токен gmail replay с логином, требуется ошибка
Google code
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
withError error: Error!) {
if let error = error {
print("\(error.localizedDescription)")
// [START_EXCLUDE silent]
NotificationCenter.default.post(
name: Notification.Name(rawValue: "ToggleAuthUINotification"), object: nil, userInfo: nil)
// [END_EXCLUDE]
} else {
// Perform any operations on signed in user here.
userRet.userId = user.userID // For client-side use only!
userRet.idToken = user.authentication.idToken // Safe to send to the server
userRet.fullName = user.profile.name
userRet.givenName = user.profile.givenName
userRet.familyName = user.profile.familyName
userRet.email = user.profile.email
userRet.accesstoken = user.authentication.accessToken
userRet.accesstoken = user.serverAuthCode
// [START_EXCLUDE]
NotificationCenter.default.post(
name: Notification.Name(rawValue: "ToggleAuthUINotification"),
object: nil,
userInfo: ["statusText": "Signed in user:\n\(userRet.fullName)"])
// [END_EXCLUDE]
}
}
Api Call
@IBAction func getDataFromApi(_ sender: Any) {
print(userRet.idToken + " " + userRet.email);
Alamofire.request("https://www.googleapis.com/gmail/v1/users/"+userRet.accesstoken+"/profile").responseJSON { response in
print("Request: \(String(describing: response.request))") // original url request
print("Response: \(String(describing: response.response))") // http url response
print("Result: \(response.result)") // response serialization result
if let json = response.result.value {
print("JSON: \(json)") // serialized json response
}
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
print("Data: \(utf8Text)") // original server data as UTF8 string
}
}
}