2013-10-25 182 views
0

我正在從https://developer.linkedin.com/oauth-test-console,i上取下標記文本框中的「oauth_token」。Linkedin分享401未授權

當我嘗試使用上述toke時,我收到「遠程服務器返回錯誤:(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 &範圍= r_basicprofile%20r_emailaddress &狀態= STATE & REDIRECT_URI = YOUR_REDIRECT_URI 從該URL我已經服用了 「代碼(查詢字符串)」並且我已嘗試過。但獲取相同的錯誤

+0

我現在有同樣的問題,當我在原始多次批准的應用程序。 linkedin會在調用api時回答401錯誤;在等待10秒或更長時間之後,新的accesstoken正常工作正常; – Shmalex

回答

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