我在 Google App Engine 中使用 python 创建了一个项目。我想在我的网站上使用谷歌登录。
我尝试使用 Google 登录网络,它运行良好,但我不知道如何从服务器进行 API 调用以确保用户已登录。
我尝试使用 users ==> user = users.get_current_user() 然后使用用户 id 进行 API 调用 ==> " https://www.googleapis.com/plus/v1/people/ "+ self.request。 get('id') +"?fields=image&key=SOME_KEY"
问题是 id 不是我应该使用的。当我比较这个id和我在javascrip中得到的id时,它们是不一样的。此外,在 Web API 中,他们提到我不应该直接将该 id 发送到服务器(我不知道原因)。所以我想知道如何在我的 python 应用程序中获得正确的 id。
// 不要直接发送到你的服务器!
<html lang="en">
<head>
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId()); // Don't send this directly to your server!
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
};
</script>
</body>
</html>