想用REST API在LinkedIn使用的ID用户数据的获取 [英] Want to fetch data of user using id in linkedin using rest api

查看:2557
本文介绍了想用REST API在LinkedIn使用的ID用户数据的获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用LinkedIn OAuth 2.0用户。在这里,我取下面下一步code中的令牌,我希望获取其电子邮件ID,我将传递一个用户的信息。但它给错误无法加载资源错误:500

下面是code:

  chrome.identity.launchWebAuthFlow({
    URL:https://www.linkedin.com/uas/oauth2/authorization?&response_type=$c$c&client_id=+ +的ClientID
                &放大器; REDIRECT_URI =EN + codeURIComponent(redirectUri)+
                &放大器;状态= 121212121                  ,互动:真实,
                },
                功能(REDIRECT_URL){
                    VAR对= redirect_url.split('/');
                    变种值= {};
                    变量code1 = redirect_url.split(?);
                    变量code2 = code1 [1] .split('和;');
                    变量code3 = code2 [0] .split('=');
                    VAR实际code = code3 [1];在请求获得//实际code
                    变种推迟= $ q.defer();
                    VAR REQ = {
                        方法:POST,
                        网址:'https://www.linkedin.com/uas/oauth2/accessToken?&grant_type=authorization_$c$c&$c$c='+实际code +
                        '和; REDIRECT_URI ='+ redirectUri +'和; CLIENT_ID ='+客户端ID +'和; client_secret ='+ clientSecretKey,
                        标题:{
                            访问控制展露报头':'X-MY-定制头,X-另一款定制头
                        }
                    }
                    $ HTTP(REQ)。然后(功能(数据){
                        deferred.resolve(数据);
                        的console.log(deferred.resolve(数据)+ data.data.access_token); //使生成的令牌                        VAR REQ2 = {
                            方法:GET,
                            网址:'https://api.linkedin.com/v1/people/email=xxxx@gmail.com:(first-name,last-name)?format=json',
                            标题:{
                                组oauth_token:data.data.access_token,
                                X丽格式':'JSON'
                            }
                        }
                        $ HTTP(REQ2)。然后(功能(数据1){
                            deferred.resolve(DATA1);
                            的console.log(sndsnd);
                            的console.log(deferred.resolve(数据)+ data1.data);
                        });
                    });
                }
            );


解决方案

你不必指定电子邮件和领域的基本配置文件数据。使用

网​​址:https://api.linkedin.com/v1/people/~?format=json

和以r_basicprofile权限得到这样名字,姓氏,ID,标题和siteStandardProfileRequest的基本细节的正确的accessToken。

用于检索额外的个人资料栏位,使用

 网​​址:https://api.linkedin.com/v1/people/~:(id,num-connections,picture-url)?format=json

有关使用r_basicprofile权限提供个人资料栏,检查的https://developer.linkedin .COM /文档/场/基本轮廓

有关用户的完整的个人资料的详细信息,您的应用需要得到LinkedIn获得使用与LinkedIn应用

https://developer.linkedin.com/docs/fields/full-profile

https://developer.linkedin.com/docs/apply-with-linkedin

应用与LinkedIn申请表:

https://help.linkedin.com/app/ask/path/ API-DVR

I am using Linkedin Oauth 2.0 . Here i have fetch the token in the code below next step is that i want to fetch info of a user whose email id i'll be passing. But its giving error unable to load resource error:500.

Below is the code:

 chrome.identity.launchWebAuthFlow({
    "url": " https://www.linkedin.com/uas/oauth2/authorization?&response_type=code&client_id=" + clientid + 
                "&redirect_uri=" + encodeURIComponent(redirectUri) +
                "&state=121212121"

                  ,'interactive': true,  
                },
                function(redirect_url) { 
                    var pairs = redirect_url.split('/');
                    var values = {};
                    var code1 = redirect_url.split('?');
                    var code2 = code1[1].split('&');
                    var code3 = code2[0].split('=');
                    var actualCode = code3[1];// actual code obtained in request
                    var deferred = $q.defer();
                    var req = {
                        method: 'POST',
                        url: 'https://www.linkedin.com/uas/oauth2/accessToken?&grant_type=authorization_code&code=' + actualCode + 
                        '&redirect_uri='+ redirectUri + '&client_id=' + clientid + '&client_secret=' + clientSecretKey,
                        headers:{
                            'Access-Control-Expose-Headers': 'X-My-Custom-Header, X-Another-Custom-Header'
                        } 
                    }
                    $http(req).then(function(data){
                        deferred.resolve(data);
                        console.log("deferred.resolve(data)"+ data.data.access_token ); // gives the token generated

                        var req2 = {
                            method: 'GET',
                            url: 'https://api.linkedin.com/v1/people/email=xxxx@gmail.com:(first-name,last-name)?format=json',
                            headers :{
                                'oauth_token': data.data.access_token,
                                'x-li-format': 'json'
                            }
                        }
                        $http(req2).then(function(data1){
                            deferred.resolve(data1);
                            console.log("sndsnd");
                            console.log("deferred.resolve(data)"+ data1.data );
                        });
                    });
                }
            );

解决方案

You dont have to specify email and fields for the basic profile data. Use

url : https://api.linkedin.com/v1/people/~?format=json

and the correct accesstoken with "r_basicprofile" permission to get the basic details like firstName, lastName, id, headline and siteStandardProfileRequest.

For retreiving additional profile fields, use

url : https://api.linkedin.com/v1/people/~:(id,num-connections,picture-url)?format=json

For available profile fields using "r_basicprofile" permission, check https://developer.linkedin.com/docs/fields/basic-profile

For full profile details of the user, your app needs to get access from Linkedin to use "Apply with Linkedin"

https://developer.linkedin.com/docs/fields/full-profile

https://developer.linkedin.com/docs/apply-with-linkedin

Apply with Linkedin application Form :

https://help.linkedin.com/app/ask/path/api-dvr

这篇关于想用REST API在LinkedIn使用的ID用户数据的获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆