2015-02-08 41 views
-1

下面的目標是喜歡一個職位!未知的身份驗證方案喜歡發佈(LinkedIn API)

我在嘗試 「像」 與REST API(LinkedIn) 後我已創建了所有範圍內的的accessToken時出現錯誤:

範圍= w_messages + rw_company_admin + rw_nus + r_emailaddress + r_basicprofile + rw_groups + r_fullprofile + r_network + r_contactinfo

我可以通過accesstoken來檢索帖子中的評論,告訴我們我已經正確地將其設置爲基準。

然而,當我試圖想用下面的代碼(只是在我收集了意見相同的代碼之後)評論,我收到此錯誤:

「未知認證方案」

我想知道爲什麼我不能在發佈所有範圍時都喜歡這篇文章,並且我也在應用程序設置中檢查了他們。還請注意,由於我可以檢索該帖子的評論,所以postID是正確的?

謝謝!

     String accessToken = "MYLONGTOKEN"; //Just dummy example 
         String postID = "g-123456-S-123456789"; //Just dummy example 
         String requestUrl = "https://api.linkedin.com/v1/posts/" + postID + "/relation-to-viewer/is-liked&oauth2_access_token=" + accessToken; 

         RestSharp.RestClient rc = new RestSharp.RestClient(); 
         RestSharp.RestRequest request = new RestSharp.RestRequest(requestUrl, RestSharp.Method.PUT); 
         request.AddHeader("Content-Type", "application/json"); 
         request.AddHeader("x-li-format", "json"); 

         request.RequestFormat = RestSharp.DataFormat.Json; 

         restResponse = (RestSharp.RestResponse)rc.Execute(request); 
         responseStatus = restResponse.ResponseStatus; 


         //unknown authentication scheme 
         MessageBox.Show(restResponse.Content.ToString()); 

回答

1

我發現了一個似乎可行的解決方案。附加和替換代碼是:

   //Comment this post 
       requestUrl = "https://api.linkedin.com/v1/posts/" + postID + "/comments?oauth2_access_token=" + accessToken; 

       var comment = new 
       { 
        text = "This is a comment!" 
       }; 

       rc = new RestSharp.RestClient(); 
       request = new RestSharp.RestRequest(requestUrl, RestSharp.Method.POST); 
       request.AddHeader("Content-Type", "application/json"); 
       request.AddHeader("x-li-format", "json"); 

       request.RequestFormat = RestSharp.DataFormat.Json; 
       request.AddBody(comment); 

       restResponse = (RestSharp.RestResponse)rc.Execute(request); 
       responseStatus = restResponse.ResponseStatus; 

       MessageBox.Show(responseStatus.ToString() + "," + restResponse.Content.ToString());