0

我正在从https://developer.linkedin.com/oauth-test-console获取访问令牌,我正在从标题文本框中获取“oauth_token”。

当我尝试使用上述令牌时,我得到“远程服务器返回错误:(401)未经授权。” 我正在使用下面的代码。

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)
    {
    }

即使我已经尝试使用 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 从这个 URL 我已经采取了“代码(查询字符串)”,我已经试过了。但得到同样的错误

4

1 回答 1

1

OAuth 测试控制台仅适用于 OAuth 1.0。oauth2_access_token 是 OAuth 2.0,它们不兼容。

无论如何,控制台的 oauth_token 是“访问代码”,应该发布到https://api.linkedin.com/uas/oauth/accessToken api。作为对您的 accessToken 请求的响应,您的 accessToken 将位于“oauth_token”字段和 oauth_token_secret 中。

然后你可以创建一个共享。控制台显示的标头应添加到您的请求中,以接收 access_token

请参考文档https://developer.linkedin.com/documents/getting-oauth-tokenhttps://developer.linkedin.com/documents/making-api-call-oauth-token调用 API

于 2013-11-19T14:45:50.937 回答