从SharePoint 2013 Web部件访问LinkedIn 2.0 API时出现403禁止错误

时间:2019-01-09 12:04:12

标签: linkedin-api

API:https://api.linkedin.com/v2/me?projection=(id,firstName,lastName)

应用许可:r_basicprofile,r_emailaddress,w_share

ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        string requesturl = "https://api.linkedin.com/v2/me?projection=(id,firstName,lastName)";


        HttpWebRequest webRequest = System.Net.WebRequest.Create(requesturl) as HttpWebRequest;
        webRequest.Method = "GET";
        webRequest.Host = "api.linkedin.com";
        //webRequest.ContentType = "application/x-www-form-urlencoded";
        //webRequest.Connection = "Keep-Alive";
        webRequest.Headers.Add("Authorization", "Bearer " + accessToken);

        //Stream dataStream = webRequest.GetRequestStream();

        //String postData = String.Empty;
        //byte[] postArray = Encoding.ASCII.GetBytes(postData);

        //dataStream.Write(postArray, 0, postArray.Length);
        //dataStream.Close();

        WebResponse response = webRequest.GetResponse();
        Stream dataStream = response.GetResponseStream();


        StreamReader responseReader = new StreamReader(dataStream);
        String returnVal = responseReader.ReadToEnd().ToString();

1 个答案:

答案 0 :(得分:0)

如果您使用的是V2 API,但您没有获得使用r_basicprofile的权限,则可以申请使用r_basicprofile进入linkedin的权限

或将r_liteprofile + r_emailaddress用于V2 (还要检查您的应用程序中是否存在r_liteprofile权限)

r_liteprofile用于firstName,lastName,profilePicture,id r_emailaddress获取电子邮件地址

检查:https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/migration-faq?context=linkedin/consumer/context