请原谅我,如果这个问题不是最好的,那就是我的第一个问题。我正在使用Google App Engine编写应用程序,我想获取登录用户的第一个和给定名称。但是,当我使用' me'来查询google plus api时userId,我得到了我的服务帐户信息,而不是登录的人。这是一个片段:
import httplib2
from google.appengine.api import memcache
from oauth2client.appengine import AppAssertionCredentials
from apiclient.discovery import build
credential_scope = 'https://www.googleapis.com/auth/plus.login'
credentials = AppAssertionCredentials(credential_scope)
http = credentials.authorize(httplib2.Http(memcache))
profile = build('plus', 'v1', http=http)
mePerson = profile.people().get(userId='me').execute(http=http)
如何询问登录人员的信息?通过对我的谷歌+用户ID进行硬编码,我能够成功获得自己的信息。此时我有用户的Gmail地址,但这是关于它的。
我也尝试过使用SignedJwtAssertionCredentials,但是我收到了以下错误:
"请求中未经授权的客户或范围。"
感谢您提供的任何帮助!
答案 0 :(得分:1)
原来我不认为这是可能的。我最终在前端解决了这个问题。这应该非常接近:
<style type="text/css">
#renderMe {
display: inline-block;
background: #4285f4;
color: white;
width: 190px;
border-radius: 5px;
white-space: nowrap;
}
</style>
<div id="renderMe" class="customGPlusSignIn">
<span class="icon"></span>
<span class="buttonText">Google</span>
</div>
<script>
var options = {
'callback': "loginFinished",
'client_id': "{{client_id}}",
'scope': 'https://www.googleapis.com/auth/userinfo.email',
'requestvisibleactions': 'http://schemas.google.com/CommentActivity http://schemas.google.com/ReviewActivity',
'cookiepolicy': 'single_host_origin'
};
$(document).ready(function() {
gapi.load('auth2', function() {
auth2 = gapi.auth2.init(options);
attachSignin(document.getElementById('renderMe'));
});
});
function attachSignin(element) {
console.log(element.id);
auth2.attachClickHandler(element, {},
loginFinished,
function(error) {
alert(JSON.stringify(error, undefined, 2));
});
}
}
function loginFinished() {
gapi.client.load('oauth2', 'v2', function()
{
gapi.client.oauth2.userinfo.get().execute(function(resp)
{
console.log("email: " + resp.email + " lastname: " + resp.family_name + " firstname: " + resp.given_name);
}
}
}
</script>