skip to Main Content

I have tried to implement a login functionality where I want to get name,email and photo of the user using Linkedin APIs, using react-native-app-auth but on clicking ‘Allow’, I am not getting back any data and neither is the WebView closing. Upon manually closing the WebView, i am getting error :

The operation couldn’t be completed. (org.openid.appauth.general error -3.)]

Code

LinkedIn Component

Tried a lot of different approaches but none of them seem to work.
I have attached the code.
Any help is appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    I have referred to resources provided by Linkedin and it worked.

    This is the code that helped me.

    Hope it helps.


  2. I don’t know it works or not in react-native. last week I worked on LinkedIn API and they changed their API endpoint and permission keyword etc.

    you can use their official package: "linkedin-api-client"
    https://github.com/linkedin-developers/linkedin-api-js-client#constructor-1

    get login URL :

    const { AuthClient } = require('linkedin-api-client');
    
    const params = {
      clientId:'',
      clientSecret:'',
      redirectUrl: '',
      enabled:true,
      logSuccessResponses:true,
      
    }
    const authClient = new AuthClient(params);
    
    
    cosnt getUrl = () => {
      let scopes = [
        'profile', 
        'email',
        'openid', 
        'w_member_social',
       ]
     const url =  authClient.generateMemberAuthorizationUrl(scopes)
    
    }

    get the url for login.

    your redirectUrl request query get a code,

    then call this functionality :

    const { AuthClient,RestliClient } = require('linkedin-api-client');
    
    const restClient = new RestliClient();
    
    exports.linkedinCallbackUrlController = async (req,res,next)=>{
      const { code } = req.query
    
        const  token = await  authClient.exchangeAuthCodeForAccessToken(code)
        
        // user info
        restClient.get({
          resourcePath: '/userinfo',
          accessToken: token.access_token
        }).then(response => {
          const profile = response.data;
          console.log("🚀 ~ file: linkedinController.js:37 ~ exports.linkedinCallbackUrlController= ~ profile:", profile)
        });
        res.json(token)
    }
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search