简体   繁体   中英

Linkedin share 401 unauthorised

I am taking the access token from https://developer.linkedin.com/oauth-test-console,i am taking " oauth_token" from header text box.

When I try with the above toke i am getting "The remote server returned an error: (401) Unauthorized." I am using below code.

try
    {

        string xml = "<share>  <comment>Check out the LinkedIn Share API!</comment>  <content>    <title>LinkedIn Developers Documentation On Using the Share API</title>";
        xml += "<description>Leverage the Share API to maximize engagement on user-generated content on LinkedIn</description>";
        xml += "<submitted-url>https://developer.linkedin.com/documents/share-api</submitted-url>";
        xml += " <submitted-image-url>http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png</submitted-image-url>  </content>  <visibility>";
        xml += " <code>anyone</code> </visibility></share>";
        string accessCodeUri = "http://api.linkedin.com/v1/people/~/shares?oauth2_access_token=generated token"; // this is session value which you get on authorization success return by linkedin
        WebRequest request = WebRequest.Create(accessCodeUri);
        request.Method = "POST";
        request.ContentType = "application/xml";
        request.ContentLength = xml.Length;
        StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
        requestWriter.Write(xml);
        requestWriter.Close();
        WebResponse webResponse = request.GetResponse();
        //success
    }
    catch (WebException exc)
    {
    }

Even i have tried with https://www.linkedin.com/uas/oauth2/authorization?response_type=code &client_id=YOUR_API_KEY &scope=r_basicprofile%20r_emailaddress &state=STATE &redirect_uri=YOUR_REDIRECT_URI from this URL i have taking the "code(query string)" and i have tried.But getting same error

The OAuth Test console is OAuth 1.0 only. The oauth2_access_token is OAuth 2.0 and they are incompatible.

Anyway the Console's oauth_token is the "Access Code" wich should be POSTed to the https://api.linkedin.com/uas/oauth/accessToken api. As a response to your request for an accessToken, your accessToken will be in the "oauth_token" field and an oauth_token_secret.

Then you can create a share. The Headers showed by Console should added to your request, to receive the access_token

Please refer to the document https://developer.linkedin.com/documents/getting-oauth-token And https://developer.linkedin.com/documents/making-api-call-oauth-token to call API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM