2013-03-24 26 views
0

有人曾經使用C#與庫RestSharpOAuthBase結合使用,以便與LinkedIn進行一些交互?LinkedIn RestSharp和OAuthBase示例

我正在尋找一個使用這些工具進行適當授權(oAuth 2.0)並在LinkedIn上使用共享API發佈帖子的工作示例。

到目前爲止,我已經成功地使用這些工具來獲取有效的訪問令牌(例如,我可以使用它來獲取個人資料信息),但是通過共享API發佈讓我卡在身份驗證上。

任何幫助將非常感謝!

回答

1

原來要簡單得多,比我在想......(不其八方通?)

主要的一點考慮是:OAuth 2.0用戶不需要簽名,現時,時間戳,授權標題...沒有。

如果您想在LinkedIn上使用sahres API和oAuth2.0發佈...... OAuthbase不是必需的。

只需按照OAuth 2.0驗證流程如下所述: http://developer.linkedin.com/documents/authentication

然後你就可以使用下面的代碼爲出發點:

var shareMsg = new 
      { 
       comment = "Testing out the LinkedIn Share API with JSON", 
       content = new 
       { 
        title = "Test post to LinkedIn", 
        submitted_url = "http://www.somewebsite.com", 
        submitted_image_url = "http://www.somewebsite.com/image.png" 
       }, 
       visibility = new 
       { 
        code = "anyone" 
       } 
      }; 

      String requestUrl = "https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=" + accessToken; 

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

      request.RequestFormat = DataFormat.Json; 
      request.AddBody(shareMsg); 

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

編碼愉快!

+0

restsharp有點酷,但你不需要在這裏使用它。你也可以使用這個代碼... http://stackoverflow.com/a/17988997/17447 – naveen 2013-08-01 08:38:21