2011-09-26 175 views
0

我正在開發Linkedin Api。 在我OAuthLinkedin.cs, 我有以下幾點:Linkedin Api遠程服務器返回錯誤:(401)未授權

 public string WebResponseGet(HttpWebRequest webRequest) 
     { 
      StreamReader responseReader = null; 
      string responseData = ""; 

      try 
      { 
       responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()); 
       responseData = responseReader.ReadToEnd(); 
      } 
      catch 
      { 
       throw; 
      } 
      finally 
      { 
       webRequest.GetResponse().GetResponseStream().Close(); 
       responseReader.Close(); 
       responseReader = null; 
      } 

      return responseData 

; } 我的代碼能夠得到一個oauthToken,oauthTokenSecret

WebResponseGet(HttpWebRequest webRequest)是它失敗的地方。 狀態:System.Net.WebExceptionStatus.Protocol錯誤遠程服務器返回錯誤:(401)未經授權。

在請求訪問linkedin的權限後,它能夠獲得令牌密碼。 但我不確定這是未經授權的錯誤。它是一些權限問題。 我在哪裏檢查這個

感謝 孫

+0

希望你在這篇文章中匿名化你的令牌機密;-) – kroonwijk

回答

2

這裏有幾件事情,你可以嘗試找出你的問題的根源:

  • 使用此OAuth的試驗檯和比較您正在生成的標題爲該工具生成的標題: https://developer.linkedin.com/oauth-test-console 如果您的標題有誤,則LinkedIn將返回401狀態

  • 如果您要求在LinkedIn中發佈XML,請確保內容類型(webRequest.ContentType)爲「application/xml」,而不是「application/x-www-form-urlencoded」,否則,LinkedIn將返回401狀態。

0

它也發生在我身上,但我想出了我做錯了什麼。

每當您創建簽名時,都會使Token和TokenSecret爲空。它爲我工作,因爲它從瀏覽器請求獲得舊的令牌和令牌密鑰。

//Generate Signature 
     string sig = this.GenerateSignature(uri, 
      this.ConsumerKey, 
      this.ConsumerSecret, 
      this.Token, 
      this.TokenSecret, 
      method.ToString(), 
      timeStamp, 
      nonce, 
      out outUrl, 
      out querystring); 
相關問題