Created
May 2, 2022 16:53
-
-
Save birinder-lobana/a326ded5f79e6710c513e9358ee9604b to your computer and use it in GitHub Desktop.
Getting started with Openscreen node SDK and create your first dynamic, trackable QR Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run the following code to test that you have successfully created a project and installed the Openscreen SDK. | |
// Initiate the Openscreen node SDK | |
const{ Openscreen }=require("@openscreen/sdk"); | |
require('dotenv').config(); | |
const os = new Openscreen().config({key: process.env.OS_API_KEY, secret: process.env.OS_API_SECRET}); | |
// Insert the project ID that you received using the Openscreen dashboard | |
const projectId ='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; | |
async function main(){ | |
// Create an asset and generate a QR Code | |
const asset =await os.project(projectId).assets().create({ | |
name:'Hello World', | |
qrCodes:[{ | |
intent:'https://openscreen.com/', | |
intentType:'DYNAMIC_REDIRECT' | |
} | |
] | |
}); | |
// Returns the asset object you just created | |
console.log("Asset:",JSON.stringify(asset,'',2)); | |
// Note: The qrCodeId within the asset object can be accessed through asset.asset.qrCodes[0].qrCodeId | |
const{ qrCodeId }= asset.asset.qrCodes[0]; | |
// Returns a scannable QR Code and saves the png file in your project folder | |
const qrCode =await os.qrCode(qrCodeId).get({format:'png', dataUrl:true}); | |
await os.saveQrImageDataToFile(qrCode,'my-first-qr-code.png'); | |
// Returns the Openscreen qrCode object | |
console.log("QR Code:",JSON.stringify(qrCode,'',2) | |
} | |
main().catch((err)=>{ | |
console.error(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment