Utilizing Window function for local variable assignment

Currently, I am facing a challenge in my Angular2 service where I am attempting to integrate the LinkedIN javascript SDK provided by script linkedin. The functionality is working as expected for retrieving data from LinkedIN, however, I am encountering an issue while trying to set the local function variable with the data received from LinkedIN.

export class LinkedInAuthService {

constructor(

) {

}

linkedInAuthorization() {
    window['IN'].User.authorize();
    window['IN'].Event.on(window['IN'], 'auth', this.getLinkedInUserInfo);
}
getLinkedInUserInfo() {
    let linkedinInfo:any;
    window['IN']
        .API
        .Raw()
        .url("/people/~:(firstName,lastName,emailAddress,industry,specialties,positions)?format=json")
        .result(function(data:any){
            console.log(data) //logs data correctly
            linkedinInfo = data 
        });
    console.log(linkedinInfo) // undefined
}

AuthLinkedInUserforGlx() {
    console.log(localStorage.getItem('linkedinInfo'))
}
}

My assumption is that the problem lies in setting linkedinInfo = data, it seems like it is not being stored locally. But I am unsure about how to address this and make it a local variable.

Answer â„–1

Success story!

class LinkedInAPI {
IN = window['IN'];
userProfile: Object;
constructor() {
    this.userProfile = JSON.parse(localStorage.getItem('profile'))
    this.IN.Event.on(this.IN, 'auth', this.fetchLinkedInData);
    console.log('Reached end of constructor')
}

verifyLinkedIn(){
    this.IN.User.authorize();
    console.log('Completed verification process')
}

fetchLinkedInData() {
    this.IN.API.Raw()
        .url("/people/~:(firstName,lastName,emailAddress,industry,specialties,positions)?format=json")
        .result((data:any) => {
            localStorage.setItem('profile', JSON.stringify(data));
            this.userProfile = data;
        });
    console.log('Data retrieval completed');
    this.AuthenticateWithGlx
}

AuthenticateWithGlx (){

}



}

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

Getting the date from a datetime JSON - here's how!

How can I extract the date from a JSON datetime string like 2013-11-09T00:00:00 using either Jquery or JavaScript? ...

The API code runs smoothly in Angular, but hits a snag when used in Ionic

Here is the API code I used to connect my application to Zoho Creator: <form method="POST" action="https://creator.zoho.com/api/batool4/xml/myapp/form/form1/record/add"> <input type="hidden" name ="authtoken" value="14e8d1c6acf83682cd9622986f0f7 ...

The return type is not undefined but the switch covers all possibilities

I'm struggling to understand the issue with this simple example interface List { "A": false, "B": false, } // The function is missing a return statement and its return type does not include 'undefined'.ts(2366) / ...

What is the process for converting the output of cryptoJS.sha256 to binary in a Postman pre-request script?

Seeking assistance in creating an HMAC signature using a pre-request script in Postman. While troubleshooting, it has become apparent that there is an issue with the signature generation process. Although a proof of concept example provides expected result ...

What is the best way to set up v-models for complex arrays or nested objects?

I'm looking to efficiently create multiple v-models for random properties within a deep array, where the position of attributes in arrays/objects can change dynamically. While I've managed to achieve my goal with the current setup, I'll need ...

What is the process of adding an array into a JSON object using the set() function in Firebase?

I am trying to add a new item to my firebase database with a specific JSON object structure: var newItem = { 'address': "Кабанбай батыр, 53", 'cityId': 1, 'courierName': "МаР...

Struggling with D3.js Angular CLI where Scope disappears within the tick() function?

Hey everyone, I'm currently in the process of incorporating a D3 visualization network graph into an Angular CLI project (http://bl.ocks.org/mbostock/1153292) using the ng2-nvd3 component. Here's the Angular component: import { Component, OnIn ...

Passing state data from parent to child components in React

I am currently facing an issue with binding the state of a parent component to a child component. Here is a snippet of the code: Parent Component: class ParentForm extends React.Component { constructor(){ super(); this ...

Eliminate unnecessary scrollbar from fancybox iframe

I am trying to display content in an iframe using Fancybox, but I am encountering an issue. Despite all the content being contained within the iframe, horizontal and vertical scroll bars are appearing. When inspecting the element in Firefox, I noticed th ...

Having trouble with jQuery UI draggable when using jQueryUI version 1.12.1?

Currently, I am diving into the world of jQuery UI. However, I am facing an issue with dragging the boxes that I have created using a combination of HTML and CSS. My setup includes HTML5 and CSS3 alongside jQuery version 1.12.1. Any suggestions or help wou ...

Is the HTML5 type of button functioning properly, while the type of submit is not working as

Looking to validate a form before running a JavaScript function? Check out this code snippet: function updateMap() { //dummy } <form> <div class="group"> <input type="number" id="hour" min="0" max="23" required> <span cl ...

How to initiate animation in Angular2 from a parent component

I am currently working on implementing an animation for a hidden element within a child component. The goal is to have the animation play when the element is displayed, as well as whenever a user clicks on a button in the parent component. Below is the si ...

Information sent by the Firefox TCP socket using the socket.send() method cannot be retrieved until the socket is closed

I am experiencing an issue while trying to send data from Firefox to a Java desktop application. My Java class functions as a server, and the Firefox script acts as a client. When I test it using another Java class called client.java, the data is successfu ...

Combining Asynchronous and Synchronous Operations in a Function: Using Cache and Ajax Requests in JavaScript

I am currently exploring how to combine two different types of returns (async / sync) from a function that is structured like this : retrieveVideo(itemID){ let data = localStorage.getItem(itemID) if ( data ) { return data; } else{ axios.ge ...

Insert multiple text box values as a new entry in an SQL database

Currently, I am implementing a code snippet to incorporate additional text boxes within a form. The main purpose is to enable users to input multiple languages they are proficient in. <script> jQuery(function($) { var i = 0; ...

What would be the most efficient method in Angular for saving and retrieving information on whether a user has previously selected a checkbox?

I am currently in the process of learning angular as I develop a web application that resembles a todo list, specifically focused on football teams. In this application, users can navigate through a menu to select a league from four options. The applicatio ...

Stop automatic selection of the last value in ng-options using AngularJS

I'm facing an issue related to AngularJS. The problem I'm encountering is that... In my code, there are two select elements. Whenever I choose an option from the first select, an Ajax call is made using ng-change to populate the second select ba ...

Tips for executing a script while updating npm version

Can a script be executed during the npm version command, after the release number has been incremented but before the git tag is created and pushed? ...

Error message occurs when trying to undo the Union operation in ArcGIS 10.2, resulting in an undefined or null reference error

I am currently working on incorporating a polygon union functionality using ArcGIS 10.2 JavaScript 3.6 API with undo and redo capabilities. The union operation works fine, but I encounter an error when attempting to undo the operation: An unhandled except ...

Angular modal not progressing past initial message due to Bootstrap integration issue

The modal functionality only seems to be working for the first message I send, as subsequent messages do not appear. My environment includes: Angular 17 Bootstrap 5.3 This is the TypeScript file snippet: import { Component } from '@angular/core&apos ...