Android + App引擎:user.getUserID()在端点中为null

use*_*896 9 authentication google-app-engine android google-cloud-endpoints

我有一个带GAE服务器的Android应用程序.我尝试按照developers.google.com中的描述对用户进行身份验证,我将用户参数添加到端点方法等.我得到一个非空的User,但此方法getUserId()返回null.它类似于这个相当老的问题: Cloud端点api中的函数User.getUserId()为非空的用户对象返回null 但是我仍然不知道如何解决它.你怎么处理这个错误?你见过它吗?

在Android客户端这里是我做的(简化):

credentials = GoogleAccountCredential.usingAudience(getApplicationContext(),         "server:client_id:" + WEB_CLIENT_ID);
credentials.setSelectedAccountName(accountName);
WarriorEntityEndpoint.Builder endpointBuilder = new WarriorEntityEndpoint.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credentials);
warriorEntityEndpoint = endpointBuilder.build();

new AsyncTask<Void, Void, Void>() {
    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        try {
            warriorEntityEndpoint.getWarrior().execute();
        } catch (Exception e) {
        }
        return null;
    }
}.execute();
Run Code Online (Sandbox Code Playgroud)

在GAE上:

@Api(name = "warriorEntityEndpoint", namespace = @ApiNamespace(ownerDomain = "szpyt.com", ownerName = "szpyt.com", packagePath = "mmorpg.monsters"),
version = "version1",
scopes = {"https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"},
clientIds = {Constants.ANDROID_CLIENT_ID, Constants.WEB_CLIENT_ID},
audiences = {Constants.ANDROID_AUDIENCE})
public class WarriorEntityEndpoint {
private static final Logger log = Logger.getLogger(WarriorEntityEndpoint.class.getName());
@ApiMethod(name = "getWarrior")
public WarriorEntity getWarrior(User user) throws OAuthRequestException, IOException  {
    log.log(Level.SEVERE, "this gives correct email: " + user.getEmail());
    log.log(Level.SEVERE, "this is null: " + user.getUserId());
Run Code Online (Sandbox Code Playgroud)

我还有另一个非常重要的问题:这个用户是否经过身份验证,如果getMail()给了我正确的帐户,但getUserId()给出了null?我读过如果没有经过身份验证,用户对象应为null,但我不确定...我正在使用App引擎SDK 1.8.7.我正在测试部署到GAE的真实设备和后端.

use*_*896 0

我想目前还没有什么好的解决办法。我将电子邮件存储为普通属性并将其从默认获取组中删除,我使用 long 作为主键(由 AppEngine 生成),并通过电子邮件属性查询实体。我不喜欢我的解决方案,如果有人可以提供,我会接受(并实施:))更好的解决方案。