Socialid.webPush.init

From Social ID Developers
(Difference between revisions)
Jump to: navigation, search
(Example)
(Usage)
 
(3 intermediate revisions by one user not shown)
Line 5: Line 5:
 
== Usage ==
 
== Usage ==
  
   socialid.login.init(appId, applicationKey, handler, options)
+
   socialid.webPush.init(appId, applicationKey, options)
  
 
== Parameters ==
 
== Parameters ==
Line 17: Line 17:
 
| width="200px" | required
 
| width="200px" | required
 
| The VAPID public key for Web Push integration. It can be found in the API Settings of your Login App. Please contact us if you already own a VAPID key pair and would like to use it instead.
 
| The VAPID public key for Web Push integration. It can be found in the API Settings of your Login App. Please contact us if you already own a VAPID key pair and would like to use it instead.
|+
 
! align="left" width="200px" | handler
 
| width="200px" | optional
 
| A callback function to handle the subscribe response. See [[socialid.webPush.subscribe | Subscribe API]] for more details.
 
 
|+
 
|+
 
! align="left" width="200px" | options
 
! align="left" width="200px" | options
Line 29: Line 25:
 
| width="200px" | optional
 
| width="200px" | optional
 
| A boolean value to inform whether the [[socialid.webPush.subscribe | Subscribe API]] should be called right after initialization or not. Default: true.
 
| A boolean value to inform whether the [[socialid.webPush.subscribe | Subscribe API]] should be called right after initialization or not. Default: true.
 +
|+
 +
! align="left" width="200px" style="padding-left: 20px" | subscribeHandler
 +
| width="200px" | optional
 +
| A callback function to handle the subscribe response. See [[socialid.webPush.subscribe | Subscribe API]] for more details.
 
|+
 
|+
 
! align="left" width="200px" style="padding-left: 20px" | serviceWorkerPath
 
! align="left" width="200px" style="padding-left: 20px" | serviceWorkerPath
Line 43: Line 43:
 
This example initializes the Web Push API with a handler for the [[socialid.webPush.subscribe | Subscribe API]].
 
This example initializes the Web Push API with a handler for the [[socialid.webPush.subscribe | Subscribe API]].
  
   socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", function(response) {
+
   var handler = function(response) {
 
     if (response.status == "success") {
 
     if (response.status == "success") {
 
       alert("You have been subscribed successfully!");
 
       alert("You have been subscribed successfully!");
Line 49: Line 49:
 
       alert("Could not subscribe you.");
 
       alert("Could not subscribe you.");
 
     }
 
     }
 +
  }
 +
  socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", {
 +
    subscribeHandler: handler
 
   });
 
   });
  
 
This example initializes the Web Push API with ''subscribeOnInit'' option disabled. Notice that you'll have to call the [[socialid.webPush.subscribe | Subscribe API]] explicitly to perform the subscription. Use this option to have more control on when to ask the user for Web Push Notification permission.
 
This example initializes the Web Push API with ''subscribeOnInit'' option disabled. Notice that you'll have to call the [[socialid.webPush.subscribe | Subscribe API]] explicitly to perform the subscription. Use this option to have more control on when to ask the user for Web Push Notification permission.
  
It also defines a custom path for the service worker script.
+
  socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", {
 +
    subscribeOnInit: false
 +
  });
 +
 
 +
This example specifies a custom path for the service worker script.
  
   socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", null, {
+
   socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", {
    subscribeOnInit: false,
+
 
     serviceWorkerPath: "/scripts/serviceWorker.js"
 
     serviceWorkerPath: "/scripts/serviceWorker.js"
 
   });
 
   });

Latest revision as of 19:38, 15 October 2020

Contents

Description

Initializes the API to be used by a Social Login application. It's required to call this function to unlock the other Web Push APIs.

Usage

 socialid.webPush.init(appId, applicationKey, options)

Parameters

appId required The identifier number of the Social Login application. The same user for the Social Login API.
applicationKey required The VAPID public key for Web Push integration. It can be found in the API Settings of your Login App. Please contact us if you already own a VAPID key pair and would like to use it instead.
options optional A Javascript object containing additional parameters.
subscribeOnInit optional A boolean value to inform whether the Subscribe API should be called right after initialization or not. Default: true.
subscribeHandler optional A callback function to handle the subscribe response. See Subscribe API for more details.
serviceWorkerPath optional The relative path for the service worker javascript file that should be hosted in the client website. Default: "/sw.js".

Example

This example initializes the Web Push API to be used by the application with id "1" with its corresponding application key.

 socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=");

This example initializes the Web Push API with a handler for the Subscribe API.

 var handler = function(response) {
   if (response.status == "success") {
     alert("You have been subscribed successfully!");
   } else {
     alert("Could not subscribe you.");
   }
 }
 socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", {
   subscribeHandler: handler
 });

This example initializes the Web Push API with subscribeOnInit option disabled. Notice that you'll have to call the Subscribe API explicitly to perform the subscription. Use this option to have more control on when to ask the user for Web Push Notification permission.

 socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", {
   subscribeOnInit: false
 });

This example specifies a custom path for the service worker script.

 socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", {
   serviceWorkerPath: "/scripts/serviceWorker.js"
 });
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox