有人曾经将 C# 与库RestSharp和OAuthBase结合使用,以便与 LinkedIn 进行一些交互吗?
我正在寻找一个使用这些工具进行适当授权(oAuth 2.0)并使用 LinkedIn 上的共享 API 发布帖子的工作示例。
到目前为止,我已经成功地使用这些工具来获取有效的访问令牌(例如,我可以使用它来获取个人资料信息),但是通过共享 API 发布让我陷入了身份验证。
任何帮助将不胜感激!
结果比我想象的要简单得多......(不是吗?)
要考虑的要点是:oAuth 2.0 不需要签名、nonce、时间戳、授权标头……这些都不需要。
如果您想使用 sahres API 并使用 oAuth2.0 在 LinkedIn 上发帖...不需要 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;
编码快乐!!