RestSharp和OAuthBase示例

RestSharp和OAuthBase示例

本文介绍了LinkedIn RestSharp和OAuthBase示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

曾经将C#与库 RestSharp OAuthBase 以便与LinkedIn进行一些交互?

anyone ever used C# in combination with the library RestSharp and OAuthBase in order get some interaction with LinkedIn?

我正在寻找一个使用这些工具进行正确授权(oAuth 2.0)并使用share API在LinkedIn上发布帖子的工作示例.

I'm looking for a working example using these tools to do proper authorization (oAuth 2.0) and to publish a post using the share API on LinkedIn.

到目前为止,我已经成功地使用这些工具来获取有效的访问令牌(例如,我可以使用它来获取个人资料信息),但是通过share API进行发布使我无法进行身份验证.

So far I've been successful using these tools to obtain valid access tokens (I can use it to obtain profile information for example), but posting via the share API got me stuck on authentication.

任何帮助将不胜感激!

推荐答案

事实证明,它比我想象的要简单得多.(不是吗?)

it turned out to be much simpler than I was thinking.... (doesn't it allways?)

要考虑的要点是:oAuth 2.0不需要签名,随机数,时间戳,授权标头...都不是.

The main point to take into account is: oAuth 2.0 does not require signatures, nonce, timestamps, authorization headers ... none of that.

如果您想使用sahres API和oAuth2.0在LinkedIn上发帖,则不需要OAuthbase.

If you want to post on LinkedIn using the sahres API and using oAuth2.0 ... OAuthbase is not needed.

只需遵循如下所述的oauth 2.0身份验证流程: http://developer.linkedin.com/documents/authentication

Simply follow the oauth 2.0 authentication flow as described here:http://developer.linkedin.com/documents/authentication

然后您可以使用以下代码作为起点:

And then you can use the following code as a starting point:

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;

编码愉快!

这篇关于LinkedIn RestSharp和OAuthBase示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 22:19