简体   繁体   English

检索 Linkedin 电子邮件地址

[英]Retrieve Linkedin email address

I'm using the Hammock library and C# to get the basic profile and email address of user from linked in following post here .我正在使用 Hammock 库和 C# 从以下帖子中链接获取用户的基本配置文件和电子邮件地址。

I've also followed these posts here and here我也在这里这里关注了这些帖子

However for the life of me I cannot get the email address of the linkedin user.然而,对于我来说,我无法获得 linkedin 用户的电子邮件地址。

Reading this linkedin post I got new created a new application to get new keys however still no luck.阅读 这篇linkedin 帖子后,我创建了一个新应用程序来获取新密钥,但仍然没有成功。

Went through this linkedin post but could not get it to work either浏览了这篇linkedin 帖子,但也无法正常工作

I'm posting the code below but it's heavily lifted form the links I followed我在下面发布代码,但它从我关注的链接中大量提升

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",
                        };

I get this screen when user navigates to linkedin.当用户导航到 linkedin 时,我会看到此屏幕。

在此处输入图像描述

To actually request the email I use this code below要实际请求电子邮件,我使用下面的代码

 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;

This is the error I get on MyInfo.Content这是我在 MyInfo.Content 上遇到的错误

在此处输入图像描述

Thanks in advance for your help.在此先感谢您的帮助。

On trying Kamyar's suggestion I get the following error message.在尝试 Kamyar 的建议时,我收到以下错误消息。 What else should I try?我还应该尝试什么?

在此处输入图像描述

Email address is accessible for the authenticated user as long as you request "r_emailaddress" permissions upon authorization.只要您在授权时请求“r_emailaddress”权限,经过身份验证的用户就可以访问电子邮件地址。

Take a look at the Oauth Login Dialog that's presented to the user to authorize the application.查看显示给用户以授权应用程序的 Oauth 登录对话框。 Notice how "email address" isn't presented as one of the profile fields that the application wants to access.请注意,“电子邮件地址”并未显示为应用程序想要访问的配置文件字段之一。 You'll need to modify this line in your code:您需要在代码中修改这一行:

var request = new RestRequest
                        {
                            Path = "requestToken?scope=r_basicprofile+r_emailaddress",
                        };

To this:对此:

var request = new RestRequest
                        {
                            Path = "requestToken?scope=r_basicprofile%20r_emailaddress",
                        };

The space should be URL encoded in your request token path.该空格应在您的请求令牌路径中进行 URL 编码。

Thanks, Kamyar Mohager谢谢, Kamyar Mohager

Update: LinkedIn has updated their API and now you can get the email address in their normal API.更新:LinkedIn 已经更新了他们的 API,现在你可以在他们的普通 API 中获取电子邮件地址。

Using JavaScript, in the head area I have:使用 JavaScript,在头部区域我有:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
  api_key: put-your-api-key-here
    authorize: true
    scope: r_basicprofile r_emailaddress
</script>
<script type="text/javascript">

function loadData() {
    IN.API.Profile("me")
        .fields(["firstName","lastName","id","emailAddress"])
        .result(function(result) {
                //$("#profile").html(JSON.stringify(result))
                $("#profile").html(JSON.stringify(result))
        });
}

</script>

and in the body I put the following:在正文中我放了以下内容:

<div id="profile">
</div>
<script type="IN/Login" data-onAuth="loadData"></script>

I have found solution.我找到了解决方案。 Simply, do not include?scope=r_emailaddres (or other permissions) to.Path property of RestRequest.简单地说,不要将?scope=r_emailaddres(或其他权限)包含到RestRequest 的.Path 属性中。 Use something like this:使用这样的东西:

Dim request = New RestRequest With {.Path = "requestToken"}
request.AddParameter("scope", "r_emailaddress")

(vb net syntax) (vb 网络语法)

.AddParameter method is the key. .AddParameter 方法是关键。

I spent days looking into this and sadly found out that LinkedIn do not expose users email address through their API, unless you have a partner agreement with them (like Microsoft, etc.)我花了几天时间研究这个问题,遗憾地发现 LinkedIn 不会通过他们的 API 公开用户的电子邮件地址,除非你与他们有合作伙伴协议(如微软等)

Knowing this your options are to use LinkedIn as an OpenId / OAuth provider and once authenticated ask them for their preferred email address.了解这一点后,您的选择是使用 LinkedIn 作为 OpenId / OAuth 提供者,并在通过身份验证后询问他们首选的电子邮件地址。

I finally got email address by using DotNetOpenAuth Api and a LinkedIn Consumer class I found at google dotnetopenauth group.我终于通过使用 DotNetOpenAuth Api 和我在 google dotnetopenauth 组找到的 LinkedIn Consumer 类获得了电子邮件地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检索具有特定电子邮件地址的用户 - Retrieve Users with specific email address 无法从MVc4中的linkedin API获取个人资料照片和电子邮件地址 - Not getting Profile Pic and Email address from linkedin api in MVc4 LinkedIn OAUTH - 仍然无法使用DotNetOpenAuth.AspNet获取电子邮件地址 - LinkedIn OAUTH - Still can't get email-address using DotNetOpenAuth.AspNet 如何获取当前用户的电子邮件地址? - How can I retrieve the current user email address? 如何从 MS Outlook 2010 中检索 CC 电子邮件地址? - How to retrieve CC email address from MS outlook 2010? 如何使用Outlook互操作检索发件人的SMTP电子邮件地址? - How to retrieve the sender smtp email address with Outlook interop? 如何从用户的电子邮件地址检索SMTP服务器? - How can I retrieve the SMTP server from the users email address? 使用ASP.NET中的Live Connect API检索用户的电子邮件地址 - Using Live Connect API in ASP.NET to retrieve a user's email address 添加Facebook登录按钮-无法在服务器端检索电子邮件地址 - Adding Facebook log in button - can't retrieve email address on server side 邮件地址已被cc电子邮件地址替换为电子邮件地址 - mailgun to email address replaced by cc email address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM