Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine GAE云端点未显示401身份验证错误_Google App Engine_Google Cloud Endpoints - Fatal编程技术网

Google app engine GAE云端点未显示401身份验证错误

Google app engine GAE云端点未显示401身份验证错误,google-app-engine,google-cloud-endpoints,Google App Engine,Google Cloud Endpoints,我试图使用身份验证来保存配置文件,但即使用户为null,GAE端点也不会给出401错误 相反,端点以200 ok响应并给出默认结果 顺便说一句,这是一部分 不幸的是,这是一个错误。修复后,转到获取更新。在第一个链接中有两个变通方法,这里引用一段话: 有两种解决方法1保存用户和从 存储,如果它引用有效帐户,则将填充用户id 这太糟糕了,因为你要为它支付保存/加载/删除成本 每个API访问都经过身份验证,即使它很小,并且 显然,一些性能成本和2你可以使用谷歌+ID 但这与用户id不同 /** *

我试图使用身份验证来保存配置文件,但即使用户为null,GAE端点也不会给出401错误

相反,端点以200 ok响应并给出默认结果

顺便说一句,这是一部分

不幸的是,这是一个错误。修复后,转到获取更新。在第一个链接中有两个变通方法,这里引用一段话:

有两种解决方法1保存用户和从 存储,如果它引用有效帐户,则将填充用户id 这太糟糕了,因为你要为它支付保存/加载/删除成本 每个API访问都经过身份验证,即使它很小,并且 显然,一些性能成本和2你可以使用谷歌+ID 但这与用户id不同

/**
 * Creates or updates a Profile object associated with the given user
 * object.
 *
 * @param user
 *            A User object injected by the cloud endpoints.
 * @param profileForm
 *            A ProfileForm object sent from the client form.
 * @return Profile object just created.
 * @throws UnauthorizedException
 *             when the User object is null.
 */

// Declare this method as a method available externally through Endpoints
@ApiMethod(name = "saveProfile", path = "profile", httpMethod = HttpMethod.POST)
// The request that invokes this method should provide data that
// conforms to the fields defined in ProfileForm

// TODO 1 Pass the ProfileForm parameter
// TODO 2 Pass the User parameter
public Profile saveProfile(final User user) throws UnauthorizedException {

    String userId = null;
    String mainEmail = null;
    String displayName = "Your name will go here";
    TeeShirtSize teeShirtSize = TeeShirtSize.NOT_SPECIFIED;

    // TODO 2
    // If the user is not logged in, throw an UnauthorizedException
    if(user== null){
        throw new UnauthorizedException("Authorization Required!");
    }
    // TODO 1
    // Set the teeShirtSize to the value sent by the ProfileForm, if sent
    // otherwise leave it as the default value

    // TODO 1
    // Set the displayName to the value sent by the ProfileForm, if sent
    // otherwise set it to null

    // TODO 2
    // Get the userId and mainEmail

    // TODO 2
    // If the displayName is null, set it to default value based on the user's email
    // by calling extractDefaultDisplayNameFromEmail(...)

    // Create a new Profile entity from the
    // userId, displayName, mainEmail and teeShirtSize
    Profile profile = new Profile(userId, displayName, mainEmail, teeShirtSize);

    // TODO 3 (In Lesson 3)
    // Save the Profile entity in the datastore

    // Return the profile
    return profile;
}