Skip to main content

User

Class

Represents a user of the current runtime.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Since Lens Scripting v378

Represents a user of the current runtime. This is the account-type-agnostic identity every Lens can rely on regardless of runtime: on Spectacles the user is backed by a Specs account (SpecsUser), in the Snapchat app by a Snapchat account (SnapchatUser). Every field is declared here, so a Lens can read the same properties on any account type; fields the backing account cannot supply are simply null. Use SafeUser#accountType when you need to branch on the kind of account rather than on a missing value.

Index

Example

global.userContextSystem.getCurrentUser(function (user) {
print("User id: " + user.userId);
if (user.name) {
print("Hi " + user.name);
}
// friendInfo is null on accounts with no friend graph, e.g. a Specs account.
if (user.friendInfo) {
print("Streak: " + user.friendInfo.streak);
}
});

Extends

Extended by

Properties

accountType

readonly accountType: AccountType

The kind of account backing this user — AccountType Snapchat or Specs. Branch on this rather than inspecting the concrete class.

Since

Lens Scripting Version 378

Example

global.userContextSystem.getCurrentUser(function (user) {
if (user.accountType === AccountType.Snapchat) {
print("Snapchat account");
} else if (user.accountType === AccountType.Specs) {
print("Specs account");
}
});

Inherited from

SafeUser.accountType


birthday

readonly birthday: UserBirthday

The user's birth month and day. The month and day will start with the index of 1. Present only when the account provides a birthdate.

Since

Lens Scripting Version 378


displayName

readonly displayName: string

The name a user has chosen to be shown as. Note that not all users set a display name, so you should treat this value as such.

Since

Lens Scripting Version 378


friendInfo

readonly friendInfo: SnapchatFriendUserInfo

Information about friendship between this user and the active user, like start date and streak. Only accounts whose runtime serves friend data populate this; it is always null for a SpecsUser, because Specs accounts have no friend graph today.

Since

Lens Scripting Version 378


hasBitmoji

readonly hasBitmoji: boolean

Whether this user has a Bitmoji that can be retrieved via BitmojiModule.

Inherited from

SafeUser.hasBitmoji


userName

readonly userName: string

The user's unique userName (@handle). Should not be relied on as a key because it can be changed.

Since

Lens Scripting Version 378


zodiac

readonly zodiac: Zodiac

This user's zodiac, derived from their birthday.

Since

Lens Scripting Version 378

Methods

getTypeName()

static getTypeName(): TypeName<User>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<User>

Since

Lens Scripting Version 378

Overrides

SafeUser.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

SafeUser.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

SafeUser.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

SafeUser.isSame