是否可以请求用户';使用DotNetOpenAuth和LinkedIn开发工具包的完整配置文件
本文关键字:开发工具 开发 LinkedIn 工具包 配置文件 DotNetOpenAuth 请求 用户 使用 是否 | 更新日期: 2025-05-08 12:06:51
使用DotNetOpenAuth请求访问令牌时,它只是对基本用户配置文件进行身份验证。
在Authorization.BeginAuthorize();
是否有某种方法可以要求用户根据其完整配置文件进行身份验证,可能是通过在令牌管理器中指定一些内容?
我知道当对LinkedIn API进行POST时,您会添加范围参数,但有没有任何方法可以使用DotNetOpenAuth和LinkedIn开发者工具包来实现这一点?
https://api.linkedin.com/uas/oauth/requestToken?scope=r_fullprofile
我还可以看到,在LinkedIn开发者工具包中,有许多完整概要文件的ProfileField枚举,所以我认为可以通过这种方式访问它们。例如
ProfileField.Industry
ProfileField.ThreeCurrentPositions
我也在寻找这样做的方法。您需要扩展领英开发者工具包。
下载源
将以下功能过载添加到WebOAuthAuthorization.cs
public void BeginAuthorize(Uri callback, IDictionary<string, string> requestParameters)
{
this.Consumer.Channel.Send(this.Consumer.PrepareRequestUserAuthorization(callback, requestParameters, null));
}
编译它并在项目中添加对它的引用(如果您正在使用NuGet包,请删除它)。然后你就可以从你的代码中调用它了,就像这样:
WebOAuthAuthentication webAuth = new WebOAuthAuthentication(LinkedInTokenManager, null);
Uri callback = new Uri("http://your.callback.uri");
Dictionary<string, string> requestParameters = new Dictionary<string, string>();
requestParameters.Add("scope", "r_fullprofile r_network");
webAuth.BeginAuthorize(callback, requestParameters);
至于第二个问题,概要文件字段ENUM用于传递到GetCurrentUser
方法(可能还有其他方法)中,以指定要返回的字段,例如
LinkedInService li = new LinkedInService(webAuth);
List<ProfileField> fields = new List<ProfileField>();
fields.Add(ProfileField.ThreeCurrentPositions);
fields.Add(ProfileField.Industry);
Person person = li.GetCurrentUser(ProfileType.Standard, fields);
然后可以在Person
对象上访问这些字段(未指定的字段为null)。