2015-02-08 82 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());