发布到LinkedIn使用共享阿比 [英] Post to Linkedin using Share Api

查看:245
本文介绍了发布到LinkedIn使用共享阿比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临在Asp.net应用程序中实现LinkedIn分享阿比困难。任何一个能帮助我吗?
  我发现了 LinkedIn分享API 文档https://developer.linkedin.com/documents/share-api )。
  这是说,我应该为共享创建一个XML,并应张贴此的URL HTTP: //api.linkedin.com/v1/people/~/shares

I'm facing difficulty in implementing LinkedIN Share Api in Asp.net application . Can any one help me ? I found the documentation for the LinkedIN Share API (https://developer.linkedin.com/documents/share-api). It is saying that i should create a XML for sharing and should post this to the URL "http://api.linkedin.com/v1/people/~/shares"

我有两个疑惑阅读本文档后

I have two doubts after reading this document


  1. 如何将令牌传递到服务器与XML一起,它不是在文档中告诉?

  2. 应该是什么XML内容,他的名字/键发布?

要求是:我需要共享一个更新(只是一个文本),以帐户连接的用户。
分享文本由用户通过文本框定的(所以将只包含文本)

Requirement is : I need to share an update ("just a text ) to a users linked in account. The text to share is given by the user through a text box(so it will only contain text)

我用 LinkedIn OAuth的库0.6.1对于认证。因为我没有找到这个库中的任何方法(即帮助后),我打算直接使用共享的API。并张贴到LinkedIn通过使用类的HttpWebRequest

I'm Using LinkedIn OAuth Library 0.6.1 For Authentication. Since i didn't find any method (that helps to post) in this library, i'm planning to use Share API directly. And Post to Linkedin by Using the class "HttpWebRequest"

我做了什么至今:

1.Created一个应用程序的链接了,所以我得到了应用程序键和应用程序键
2.In为了验证,将用户重定向到在OAuth库中使用BeginAuthMethod链接0.6.1这样

1.Created a app in linked in, so i got App-Key and App-Key 2.In order to Authenticate, redirects the user to linked in using the BeginAuthMethod in the OAuth Library 0.6.1 like this

var token = OAuthManager.Current.CreateToken(callback: this.AppRedirectUrl);
OAuthManager.Current.BeginAuth (token, endResponse: true, displayAllowDenyScreen: false);

3.After验证我收到的链接的反应和我使用的身份验证令牌来获取这样的usertoken

3.After Authentication i receive the response from linked in and i use that auth-token to fetch the usertoken like this

var token = OAuthManager.Current.GetTokenInCallback();
var session = OAuthManager.Current.CompleteAuth(token);
this.UserToken = token.Token;
this.UserSecret = token.TokenSecret;

4。我创建了一个XML有点像这样的:

4.I have created a XML somewhat like this :

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<share>
    <comment>83% of employers will use social media to hire: 78% LinkedIn, 55% Facebook, 45% Twitter [SF Biz Times] http://bit.ly/cCpeOD</comment>
    <content>
         <title>Survey: Social networks top hiring tool - San Francisco Business Times</title>
    </content>
    <visibility>
        <code>anyone</code>
    </visibility>
</share>

5.So现在我有应用程序键,应用程序,秘密,用户令牌和用户的秘密,和我有XML和URL后(即 http://api.linkedin.com/v1/people/~/shares

如何发布该XML使用令牌的网址?任何一个可以给予一定的/这方面的任何信息?

How to post this xml to the url using the tokens?. Can any one give some/any information regarding this?

我碰到一个例子,Java出现这样做。链接是 https://developer.linkedin.com/documents/writing-linkedin-apis 。但我需要这在.NET

I came across an example in java doing the same. the link is "https://developer.linkedin.com/documents/writing-linkedin-apis".But i need this in .NET

推荐答案

使用这个方法来发布到LinkedIn股票。该方法假定您有的accessToken 派上用场了。

Use this method to post to LinkedIn shares. The method assumes that you have the accesstoken handy.

private string linkedinSharesEndPoint = "https://api.linkedin.com/v1/people/~/shares?oauth2_access_token={0}";
private const string defaultUrl = "some-url";
private const string defaultImageUrl = "some-image-url";

public bool PostLinkedInNetworkUpdate(string accessToken, string title, string submittedUrl = defaultUrl, string submittedImageUrl = defaultImageUrl)
{
    var requestUrl = String.Format(linkedinSharesEndPoint, accessToken);
    var message = new
    {
        comment = "Testing out the LinkedIn Share API with JSON",
        content = new Dictionary<string, string>
        { { "title", title },
            { "submitted-url", submittedUrl },
            {"submitted-image-url" , submittedImageUrl}
        },
        visibility = new
        {
            code = "anyone"
        }
    };

    var requestJson = new JavaScriptSerializer().Serialize(message);

    var client = new WebClient();
    var requestHeaders = new NameValueCollection
    {
        { "Content-Type", "application/json" },
        { "x-li-format", "json" }
    };
    client.Headers.Add(requestHeaders);
    var responseJson = client.UploadString(requestUrl, "POST", requestJson);
    var response = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(responseJson);
    return response.ContainsKey("updateKey");
}

请注意,我已经做了 submittedUrl submittedImageUrl 可选。

Please note that I have made the submittedUrl and the submittedImageUrl optional.

这篇关于发布到LinkedIn使用共享阿比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆