簡體   English   中英

Linkedin Api遠程服務器返回錯誤:(401)未經授權

[英]Linkedin Api The remote server returned an error: (401) Unauthorized

我正在使用Linkedin Api。 在我的OAuthLinkedin.cs中,我有以下內容:

        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的權限后,它可以獲得令牌秘密。 但我不確定這個未經授權的錯誤。 是一些許可問題。 我在哪里檢查這個

謝謝孫

以下是您可以嘗試確定問題根源的一些事項:

  • 使用此OAuth測試控制台並將您生成的標頭與此工具生成的標頭進行比較: https//developer.linkedin.com/oauth-test-console如果您的標頭錯誤,那么LinkedIn將返回401狀態

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

它也發生在我身上,但我弄清楚我做錯了什么。

每當您創建簽名時,令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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM