使用Sparkle.LinkedInNET的LinkedIn API v2:检索摘要和技能

时间:2017-12-15 19:40:23

标签: c# api linkedin

我正在实施一个LinkedIn API阅读器来获取用户的摘要和技能。 OAuth2身份验证过程运行正常,但当我尝试检索配置文件对象时,我被困在这里:

public void OAuth2(string code, string state, string error, string error_description)
{
    // create a configuration object
    var config = new LinkedInApiConfiguration("api-key", "api-secret-code");

    // get the APIs client
    var api = new LinkedInApi(config);

    if(!string.IsNullOrEmpty(error) || !string.IsNullOrEmpty(error_description))
    {
        // handle error and error_description
    }
    else
    {
        var redirectUrl = "http://mywebsite/LinkedIn/OAuth2";
        var userToken = api.OAuth2.GetAccessToken(code, redirectUrl);


        var user = new UserAuthorization(userToken.AccessToken);
        var profile = api.Profiles.GetMyProfile(user); //Here I don't know what to pass as acceptLanguages and FieldSelector!!
    }    
}

没有任何参数对应于'ProfilesApi.GetMyProfile(UserAuthorization,string [],FieldSelector)'

所需的形式参数'acceptLanguages'

我试图从Sparkle.LinkedIn Api项目中理解,但没有文档。

我只想检索摘要和技能字段。

1 个答案:

答案 0 :(得分:1)

通过创建一个包含语言代码的简单数组和一个FIeldSelector变量来解决:

var acceptLanguages = new string[] { "it-IT","en-US", };
var fields = FieldSelector.For<Person>()
            .WithId()
            .WithFirstName()
            .WithLastName()
            .WithFormattedName()
            .WithEmailAddress()
            .WithHeadline()
            .WithLocationName()
            .WithLocationCountryCode()
            .WithPictureUrl()
            .WithPublicProfileUrl()
            .WithSummary();
Person profile = api.Profiles.GetMyProfile(user,acceptLanguages,fields);