DeepLinkModule
ClassThe DeepLinkModule brings the concept of deep linking, familiar from mobile platforms like Android and iOS, to Spectacles.
- Snapchat: not supported
- SPECS: fully supported
- Camera Kit Web: not supported
- Camera Kit Mobile: not supported
- SnapchatNot supported — Available on SPECS only
- SPECSFully supported
- Camera Kit WebNot supported — Available on SPECS only
- Camera Kit MobileNot supported — Available on SPECS only
The DeepLinkModule brings the concept of deep linking, familiar from mobile platforms like Android and iOS, to Spectacles. This module allows Lenses to send and receive deep link URIs between Spectacles and the Spectacles App.
Index
Properties
Methods
Example
const deepLink = require("LensStudio:DeepLinkModule");
// Configuration for Google OAuth2
const clientId = "YOUR_GOOGLE_CLIENT_ID";
const redirectUri = "YOUR_APP_REDIRECT_URI"; // Make sure this is registered in Google developer console
const scope = "https://www.googleapis.com/auth/userinfo.profile"; // Adjust scope as needed
// Register an event handler to handle when a deep link URI is received
deepLink.onUriReceived.add((event) => {
console.log(`Deep link received: ${event.uri}`);
// Extract the authorization code using string manipulation
const queryString = event.uri.split('?')[1];
const params = queryString.split('&');
let authorizationCode = null;
for (const param of params) {
const [key, value] = param.split('=');
if (key === 'code') {
authorizationCode = decodeURIComponent(value);
break;
}
}
if (authorizationCode) {
console.log(`Authorization code received: ${authorizationCode}`);
// Exchange authorization code for access token
exchangeAuthorizationCodeForAccessToken(authorizationCode);
} else {
console.error("Authorization code not found in URI");
}
});
// Function to start the OAuth2 flow by opening a deep link to Google's OAuth2 page
function authenticateWithGoogle() {
const oauthUri = `https://accounts.google.com/o/oauth2/v2/auth` +
`?response_type=code` +
`&client_id=${encodeURIComponent(clientId)}` +
`&redirect_uri=${encodeURIComponent(redirectUri)}` +
`&scope=${encodeURIComponent(scope)}`;
deepLink.openUri(oauthUri)
.then(() => {
console.log('Deep link opened successfully');
})
.catch((error) => {
console.error('Failed to open deep link:', error);
});
}
// Placeholder function for exchanging authorization code for access token
function exchangeAuthorizationCodeForAccessToken(code: string) {
console.log(`Exchanging authorization code for access token: ${code}`);
// Implement server-side logic to exchange code for access token
// Send a POST request to Google's token endpoint with `code`, `clientId`, `redirectUri`, and `clientSecret`
}
// Call this function to begin OAuth2 authentication with Google
authenticateWithGoogle();
Extends
Properties
name
name:
string
The name of the Asset in Lens Studio.
Default Value
""
Inherited from
onUriReceived
readonlyonUriReceived:event1<DeepLinkUriReceivedArgs,void>
SPECS
An event triggered when a deep link request is received by the Lens from SnapOS, enabling the lens to process and respond to the incoming action or content linked by the URI.
uniqueIdentifier
readonlyuniqueIdentifier:string
Since
Lens Scripting Version 176
Inherited from
Methods
getTypeName()
staticgetTypeName():TypeName<DeepLinkModule>
SPECS
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<DeepLinkModule>
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
openUri()
openUri(
uri):Promise<void>
SPECS
Initiates a deep link request by sending a specified URI from the Lens to SnapOS, allowing dynamic interaction based on the URI’s target action or content.
Parameters
| Parameter | Type |
|---|---|
uri | string |
Returns
Promise<void>