Leverage the LinkedIn javascript API by passing a dynamic parameter

Is there a way to dynamically pass an API key to the LinkedIn Library call?

I am retrieving the API key from a database field and storing it in a global JavaScript variable called 'myJavascriptVariable'. However, when I try to pass it to the API upon loading, it is not accepting it and throwing an exception.

What should be my next steps?

 <script type="text/javascript" src="//platform.linkedin.com/in.js?async=false">
        api_key:   myJavascriptVariable
        credentials_cookie: true
        authorize: true
</script>

UPDATE: The error message states "You must specify a valid JavaScript API Domain as part of this key's configuration."

Answer №1

The script element's content is not JavaScript, but rather a configuration file utilized by LinkedIn's JavaScript system. This file does not allow for the use of variables.

If you attempt to modify the configuration data using a JavaScript variable (such as through innerHTML), your timing would need to be precise in order to intercept it before LinkedIn's JS processes it (typically happening before the load event triggers).

It would be more effective to generate this content on the server side instead.

Answer №2

One way to handle this situation is by generating the script tag dynamically once you have retrieved the variable.

var LIScript = document.createElement('script');
LIScript.type = 'text/javascript';
LIScript.src = '//platform.linkedin.com/in.js?async=false';
LIScript.text = "api_key:  "+myJavascriptVariable+"
        credentials_cookie: true
        authorize: true";

document.getElementsByTagName('head')[0].appendChild(LIScript);

Using the defer and async attributes may help in managing when the script gets executed during the loading process, although it's not a guaranteed solution for your specific issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Acquiring the root URL with the $location service in AngularJS

I am facing a situation where I have a specific URL structure like the one shown below. http://localhost:8080/test#/users/list Upon further investigation, I discovered the following information: $location.url() returns -> "users/list" $location.path( ...

Printing the HTML Template of a widget with multiple loops results in a blank first page being displayed

I have encountered an issue while working with a table and ng-repeat loops in my report widget. The table displays fine on the screen, but when I try to print it, there is always a blank page at the beginning. Interestingly, if I remove the second and thir ...

I am currently familiarizing myself with backend routes and everything seems to be going smoothly for the first time around. However, upon attempting to revisit the site for

https://i.sstatic.net/ZOBl6.png https://i.sstatic.net/Xzhej.png Whenever I navigate from the home page to the contact page and then back to the home page, it displays an error message saying the site can't be reached. var http = require("http&q ...

Caller Function's Parents in JavaScript

I have functions in JavaScript that need to verify if they are being called by the correct function (for example, it requires the function something.stuff.morestuff.coolFunction to initiate it). I attempted using Function.caller, but it only gives me the f ...

How to access selection range styles using JavaScript

It is common knowledge that we can retrieve the selection of text in JavaScript using the following method: var range = window.getSelection (); However, how can we obtain the style of this selection? For example, when I select bolded text or italicized ...

"Modifying state within a child component and utilizing the refreshed value in the parent component

I'm currently working on creating a simple header mini cart with a cart item counter in NextJS. I'm utilizing the form state value in the header component and then passing that value to the child components of the header where the numerical quant ...

Managing dynamically loaded scripts in Meteor.js

This poses an interesting query: is there a way to regulate which scripts a client is provided with? I've partitioned my code into dynamically loadable segments using the import('dynamically_loadable_file') method, but each time it's ca ...

Node.js and MongoDB Login Form Integration with Mongoose

I am relatively new to web development and currently working on a simple web page for user login authentication. My goal is to verify user credentials (username & password) on the LoginPage from a mongoose database, and if they are correct, redirect them t ...

Attempting to replicate the functionality of double buffering using JavaScript

In my HTML project, I have a complex element that resembles a calendar, with numerous nested divs. I need to refresh this view in the background whenever there are updates on the server. To achieve this, I set up an EventSource to check for data changes on ...

Converting an object with a combination of different index types into a string representation

I'm dealing with a unique object structure that behaves similarly to an array, except it contains a mix of index types (numbers and strings). Here's an example: var myObj = []; myObj[0] = 'a'; myObj[1] = 'b'; myObj[2] = &apos ...

How to pass the ng-repeat $index value as a parameter in AngularJS

Within the code snippet provided, there is a shell page index.html and a partial view currently utilized by two different controllers. The static data in AppController is connected to the list.html partial view and displayed as a table. In the JavaScript p ...

What characteristics do you use to distinguish a non-compiled language?

Curiosity strikes me as I notice a common theme of "personal preference" regarding the distinctions between "Scripting Language" and "Programming Language". Here is my query: Is there a specific technical term for a language that operates without the nee ...

VueJS component experiencing stagnant DOM updates

I have reviewed similar posts on "DOM not updating", but have yet to find a solution. I am working on a task app and it can successfully load, add, and delete tasks from Firestore. However, I'm facing two issues and would like to address the first one ...

Incorporating code execution during promise completion

I'm currently working on an express application that involves a generator function which takes approximately 5 minutes to process a large amount of data. Unfortunately, I am unable to optimize this function any further. Express has a built-in ti ...

Update the gulp watch function to use gulp@4

We are currently in the process of transitioning from <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fb9c8e978bbbc8d5c2d5ca">[email protected]</a> to gulp@4, and encountering difficulties during the switch. Upon r ...

React DataGrid fails to refresh when state changes

Currently, I am in the process of developing a link tree using the Datagrid Component provided by MaterialUI. While data can be successfully displayed, I encounter an issue when attempting to add a new entry. The problem lies in the fact that despite cha ...

The i18n feature in Nuxt 3 retrieves language locales from an external API

While working on my Nuxt 3 app, I encountered an issue when trying to integrate i18n. Despite conducting extensive research, I couldn't find any helpful information, hence I have a question. I am utilizing i18n with Prismic CMS. The locales array is s ...

Why is my jQuery script only functioning in Firefox?

<!DOCTYPE html> <html> <head> <title>testing</title> <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.min.js"></script> </head> <body> <div id="div1">content1& ...

Using Angular to implement a decimal pipe on an input field

I am looking for a way to display comma-separated numbers as the user types in an input field by applying the decimal pipe. I have experimented with ngx-mask, but it seems to only function when the user physically enters the numbers. However, when I manu ...

Steps to emphasize HTML content and store it in the database for later use

I am currently working on a project that involves highlighting selected text within an HTML page that is loaded using PHP + XSL transformation. While I have come across solutions for highlighting the current selected text, I require the functionality to sa ...