我正在使用 Hammock 库和 C# 来获取用户的基本个人资料和电子邮件地址,链接在此处的以下帖子中。
但是对于我的一生,我无法获得linkedin用户的电子邮件地址。
阅读这个linkedin帖子我得到了新的创建一个新的应用程序来获取新的密钥但是仍然没有运气。
浏览了这个linkedin帖子,但也无法让它工作
我在下面发布了代码,但是从我关注的链接中大大提升了
var credentials = new OAuthCredentials
{
CallbackUrl = "http://localhost:2715/Callback.aspx",
ConsumerKey = "my consumer key",//not shown
ConsumerSecret = "my consumer secret",//not shown
Type = OAuthType.RequestToken,
};
var client = new RestClient
{
Authority = "https://api.linkedin.com/uas/oauth",
Credentials = credentials
};
//var scope = HttpUtility.UrlEncode("r_basicprofile r_emailaddress");
var request = new RestRequest
{
Path = "requestToken?scope=r_basicprofile+r_emailaddress",
};
当用户导航到linkedin 时,我会看到此屏幕。
要实际请求电子邮件,我使用下面的代码
var request = new RestRequest { Path = "people/~/email-address" };
var credentials = new Hammock.Authentication.OAuth.OAuthCredentials
{
Type = OAuthType.AccessToken,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = "my consumer key", //not shown
ConsumerSecret = "my consumer secret", //not shown
Token = Session["AccessToken"].ToString(),
TokenSecret = Session["AccessSecretToken"].ToString(),
Verifier = Session["Verifier"].ToString()
};
var client = new RestClient()
{
Authority = "http://api.linkedin.com/v1/",
Credentials = credentials,
Method = WebMethod.Get
};
var MyInfo = client.Request(request);
String content = MyInfo.Content;
这是我在 MyInfo.Content 上遇到的错误
在此先感谢您的帮助。
在尝试 Kamyar 的建议时,我收到以下错误消息。我还应该尝试什么?