本文介绍了安卓+应用程序引擎:user.getUserID()是在端点空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个Android应用程序与GAE服务器。我试图描述developers.google.com上对用户进行认证,我添加的用户参数设置为端点的方法等。我得到),用户是不为空,但这种方法getUserId(返回null。它是与此类似,而老问题:Function User.getUserId()云终端API为用户对象,它是不是null 返回null但我还是不知道如何解决它。你如何处理这个错误?你有没有遇到过?

I have an Android application with GAE server. I tried to authenticate the user as described on developers.google.com, I added the user parameter to the endpoint methods etc. I get a User which is not null, but this method getUserId() returns null. It is similar to this, rather old problem:Function User.getUserId() in Cloud endpoint api returns null for a user object that is not nullBut I still don't know how to work around it. How do you handle this error? Have you ever encountered it?

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

In android client here's what I did (its simplified) :

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();

和在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());

我还另一个非常重要的问题:是该用户认证,如果getMail()给了我正确的帐户,但getUserId()给出空?我读了用户对象为空,如果它没有经过认证,但我不知道任何更多...我使用的App Engine SDK 1.8.7。我测试一个真实的设备和后端部署到GAE上。

I have also another very important question: is this user authenticated, if getMail() gives me correct account, but getUserId() gives null? I read that user object should be null if it was not authenticated but I am not sure any more...I'm using App engine SDK 1.8.7. I'm testing on a real device and backend deployed to GAE.

推荐答案

我想有它现在没有很好的解决方案。我保存电子邮件作为一个正常的财产和默认删除它提取组,我用只要一个主键(由AppEngine上生成的),我的E-mail属性查询实体。我不喜欢我的解决方案,我会接受(并实现:))一个更好的,如果任何人都可以提供。

I guess there is no good solution for it right now. I store e-mail as a normal property and remove it from default fetch group, I use long as a primary key (generated by AppEngine) and I query the entity by the e-mail property. I don't like my solution, I'll accept ( and implement :) ) a better one if anyone can provide.

这篇关于安卓+应用程序引擎:user.getUserID()是在端点空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 16:27