Lens Scripting API
    Preparing search index...

    Class DeepLinkModuleWearable 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.

    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();

    Hierarchy (View Summary)

    Index

    Properties

    name: string

    The name of the Asset in Lens Studio.

    onUriReceived: event1<DeepLinkUriReceivedArgs, void>

    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: string

    Methods

    • Returns the name of this object's type.

      Returns string

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

      Parameters

      • type: string

      Returns boolean

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

      Parameters

      Returns boolean

    • Wearable Only

      Initiates a deep link request by sending a specified URI from the Lens to SnapOS, allowing dynamic interaction based on the URIs target action or content.

      Parameters

      • uri: string

      Returns Promise<void>