获取LinkedIn个人资料图片

Geo*_*mbe 50 api linkedin

有没有简单的方法来获取用户LinkedIn个人资料照片?

理想情况下与Facebook的相似 - http://graph.facebook.com/userid/picture

小智 51

您可以使用此调用检索原始照片尺寸:

http://api.linkedin.com/v1/people/~/picture-urls::(original)

请注意,这可能是任何大小,因此您需要在您身边进行缩放,但图像是用户上传的原始图像.

  • 一个小小的点 - 图像是'用户上传的原始图像'...在角落添加了一个linkedIn徽标:) (13认同)
  • 你能以更简单的方式解释一下吗? (2认同)
  • 似乎LinkedIn现已完全禁用检索大图片,因为响应此请求我得到一个空的<pictureurls />标签,而常规配置文件API调用仅获得100x100图片。 (2认同)

Ada*_*erg 33

不那么容易......你需要通过OAuth,然后代表会员,你要求:

http://api.linkedin.com/v1/people/{user-id}/picture-url

  • 这是一个耻辱,希望有一个更容易的机制. (11认同)
  • saintmac.不,如果你只想要hte图片,只需拨打此网址即可.{user-id}是一个变量,"picture-url"是您放入网址以获取图片的实际文本.但是在我的测试中,这会返回较小的图片而不是原始图片.我推荐下面的答案使用picture-urls ::(原创) (2认同)
  • 它没有显示图像.我可能会做错事.有什么帮助吗? (2认同)
  • 在2016年对我有用,你可能需要https而不是http和Authorization标头,使用Bearer access_token,所以在你的http标题中输入"Authorization":"Bearer <access_token>" (2认同)

Mad*_*ota 10

完成使用OAuth 2.x 的Linkedin 用户身份验证后,向人员URL发出请求.

https://api.linkedin.com/v1/people/~:(id,email-address,first-name,last-name,formatted-name,picture-url)?format=json

其中~代表当前经过身份验证的用户.响应将是这样的......

{
  "id": "KPxRFxLxuX",
  "emailAddress": "johndoe@example.com",
  "firstName": "John",
  "lastName": "Doe",
  "formattedName": "John Doe",
  "pictureUrl": "https://media.licdn.com/mpr/mprx/0_0QblxThAqcTCt8rrncxxO5JAr...cjSsn6gRQ2b"
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!

  • 你如何获得更大尺寸的照片呢?我得到的是超小:/ (2认同)

小智 10

如果您使用API​​的2.0版本(所有开发人员都需要在2019年3月1日之前进行迁移),则应使用投射来扩展profilePicture.displayImage。如果执行此操作,则将在其中包含完整的JSON元素displayImage~(“〜”不是错字),profilePicture其中包含您可能需要的所有信息。

https://api.linkedin.com/v2/me?projection=(id,profilePicture(displayImage~:playableStreams))

您可以在Profile Picture API文档中查看更多信息,以查看JSON响应或Profile API文档


小智 6

我在我的解决方案中使用OWIN,因此在用户允许您的应用程序使用LinkedIn凭据后,可以使用简单而简单的GET请求来访问URL https://api.linkedin.com/v1/people/~:(picture-url)?format=json如前所述,请求标题中的Bearer授权解决了我的问题.

我的Startup.Auth.cs文件

var linkedInOptions = new LinkedInAuthenticationOptions()
{
   ClientId = [ClientID],
   ClientSecret = [ClientSecret],
   Provider = new LinkedInAuthenticationProvider()
   {
      OnAuthenticated = (context) =>
      {
          // This is the access token received by your application after user allows use LinkedIn credentials
          context.Identity.AddClaim(new Claim(
              "urn:linkedin:accesstoken", context.AccessToken));
          context.Identity.AddClaim(new Claim(
              "urn:linkedin:name", context.Name));
          context.Identity.AddClaim(new Claim(
              "urn:linkedin:username", context.UserName));
          context.Identity.AddClaim(new Claim(
              "urn:linkedin:email", context.Email));
          context.Identity.AddClaim(new Claim(
              "urn:linkedin:id", context.Id));

          return Task.FromResult(0);
      }
   }
};

app.UseLinkedInAuthentication(linkedInOptions);
Run Code Online (Sandbox Code Playgroud)

我在LinkedIn中获取用户个人资料图片的方法:

public string GetUserPhotoUrl(string accessToken)
{
   string result = string.Empty;
   var apiRequestUri = new Uri("https://api.linkedin.com/v1/people/~:(picture-url)?format=json");
   using (var webClient = new WebClient())
   {
      webClient.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + accessToken);
      var json = webClient.DownloadString(apiRequestUri);
      dynamic x = JsonConvert.DeserializeObject(json);
      string userPicture = x.pictureUrl;
      result = userPicture;
   }
   return result;
}
Run Code Online (Sandbox Code Playgroud)

最后我的动作片段消耗了上面的方法:

public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
   ...
   var externalIdentity = HttpContext.GetOwinContext().Authentication.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);
   string accessToken =
               externalIdentity.Result.Claims.FirstOrDefault(c => c.Type == "urn:linkedin:accesstoken").Value;
   model.PhotoUrl = GetUserPhotoUrl(accessToken);
   ...
}
Run Code Online (Sandbox Code Playgroud)

我希望它可以提供帮助.最好的祝福