当前位置: 首页 > 知识库问答 >
问题:

Google App Engine云终结点用户ID为空

冯胤
2023-03-14

我正在使用本课程中的一个(稍加修改的)变通方法来获取userId,如果请求是从Android客户端发送的,则userId为空。

/**
 * This is an ugly workaround for null userId for Android clients.
 *
 * @param user A User object injected by the cloud endpoints.
 * @return the App Engine userId for the user.
 */
private static String getUserId(User user) {
    String userId = user.getUserId();
    if (userId == null) {
        LOG.info("userId is null, so trying to obtain it from the datastore.");
        AppEngineUser appEngineUser = new AppEngineUser(user);
        ofy().save().entity(appEngineUser).now();

        AppEngineUser savedUser = ofy().load().key(appEngineUser.getKey()).now();
        userId = savedUser.getUser().getUserId();
        LOG.info("Obtained the userId: " + userId);
    }
    return userId;
}

但我无法获取用户ID。

INFO: Obtained the userId: null

这个变通方法已经在其他项目中完美地工作了,所以问题一定在其他地方。My endpoints api使用以下范围、客户和受众进行了注释:

scopes = {
            Constants.EMAIL_SCOPE
    },
    clientIds = {
            Constants.API_EXPLORER_CLIENT_ID,
            Constants.WEB_CLIENT_ID,
            Constants.ANDROID_CLIENT_ID
    },
    audiences = {
            Constants.ANDROID_AUDIENCE
    }

constants.android_pavientconstants.web_client_id是相同的。我没有使用web客户端,但Google告诉我添加web客户端ID。这个客户端id是否需要指定重定向URI和javascript源?

mCredential = GoogleAccountCredential.usingAudience(
        EndpointService.this,
        "server:client_id:IDIDIDID.apps.googleusercontent.com"
);

共有1个答案

夹谷衡
2023-03-14

我才明白为什么这个变通办法管用。我需要开始一个新的objectify会话,以便不使用缓存,并且可以填充userId。

Objectify objectify = ofy().factory().begin();
AppEngineUser savedUser = objectify.load();
 类似资料:
  • 我有一个班级组织,只有很少的字段,如下所示。 为了在客户端以简单的方式处理日期,我将转换为,并使用这些JsonSerializer将其发送给客户端,如下所示 我有一个endpoint,它将执行get organization并像下面这样在响应映射中插入结果。 但是我在客户端看到的最终结果JSON是 这里的日期以某种形式出现,而不是很长。如果我使用Jackson转换相同的数据,而不使用云endpoi

  • 如何注册一个新用户,而不通过管理员,keycloak提供了一个界面来注册一个新的用户URL,以便直接在浏览器中注册新用户: http://localhost:8080/auth/realms/myrealm/login-行动/注册?客户id=clientid 但我找不到注册的rest API的endpoint。我成功地使用admin rest API添加了一个用户,但我想注册一个新用户,但不提及a

  • 我正在使用apache camel,希望有多条路由。路线如下。

  • 我对普罗米修斯使用千分尺度量,根据文档:http://micrometer.io/docs/prometheus#_configuring 如何像那样将其连接到另一个endpoint?

  • 在 Serenity 中,服务终结点是 ASP.NET MVC 控制器的一个子类。 这是 Northwind 的 OrderEndpoint 摘录: namespace Serene.Northwind.Endpoints { [RoutePrefix("Services/Northwind/Order"), Route("{action}")] [ConnectionKey("N

  • 终端云服务2周前入池的🐮友们有消息了吗,鼠鼠等不及啦😖