Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



User Objects

An instance of the User class represents a user. User instances are unique and comparable. If two instances are equal, then they represent the same user.

The application can access the User instance for the current user by calling the UserService::getCurrentUser() function.

use google\appengine\api\users\User;
use google\appengine\api\users\UserService;

$user = UserService::getCurrentUser();
if (!isset($user)) {
  // The user is not logged in
} else {
  echo 'Hello, ' . $user->getNickname();
}

You can use the UserService::getCurrentUser() function no matter which authentication option your app uses.

A User instance can be also constructed from an email address:

$user = new User("[email protected]");

Or, if you have a federated_identity , you can use it to create a User instance:

$user = new User(null, "http://example.com/id/ajohnson");

If the User::__construct() is called with an email address that does not correspond with a valid Google account, the object will be created but it will not correspond with a real Google account. This will be the case even if someone creates a Google account with the given email address after the object is stored. A User value with an email address that does not represent a Google account at the time it is created will never match a User value that represents a real user.

The User object for a valid user can provide a unique ID value for the user that stays the same even if the user changes her email address. The getUserId() method returns this ID, a string value.

The User object has the same form no matter which method of authentication your app uses. If you switch authentication options from Google Accounts to OpenID, existing User objects in the datastore are still valid.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.