【发布时间】:2011-08-05 11:39:34
【问题描述】:
有没有一种简单的方法来获取用户的 LinkedIn 个人资料照片?
与您使用 Facebook 的方式非常相似 - http://graph.facebook.com/userid/picture
【问题讨论】:
-
记下下面的ccoloma's answer,因为这与API 的
v2发生了很多的变化。接受和投票最多的答案是v1,很快就会被弃用。
有没有一种简单的方法来获取用户的 LinkedIn 个人资料照片?
与您使用 Facebook 的方式非常相似 - http://graph.facebook.com/userid/picture
【问题讨论】:
v2 发生了很多的变化。接受和投票最多的答案是v1,很快就会被弃用。
您可以通过此调用检索原始照片尺寸:
http://api.linkedin.com/v1/people/~/picture-urls::(original)
请注意,这可以是任意大小,因此您需要在自己的一侧进行缩放,但图像是用户上传的原始图像。
【讨论】:
picture-url 而不是picture-urls::(original)
没那么容易...你需要通过 OAuth,然后代表会员,你要求:
http://api.linkedin.com/v1/people/{user-id}/picture-url
【讨论】:
如果你使用2.0版本的API(所有开发者都需要迁移by March 1, 2019),你应该使用投影扩展profilePicture.displayImage。如果您这样做,您将在 profilePicture 内拥有一个完整的 JSON 元素 displayImage~(“~”不是错字),其中包含您可能需要的所有信息。
https://api.linkedin.com/v2/me?projection=(id,profilePicture(displayImage~:playableStreams))
您可以在Profile Picture API doc 查看更多内容以查看 JSON 响应或the Profile API doc。
【讨论】:
使用 OAuth 2.x 完成 Linkedin 用户身份验证后,向人员 URL 发出请求。
~ 代表当前经过身份验证的用户。响应将是这样的......
{
"id": "KPxRFxLxuX",
"emailAddress": "johndoe@example.com",
"firstName": "John",
"lastName": "Doe",
"formattedName": "John Doe",
"pictureUrl": "https://media.licdn.com/mpr/mprx/0_0QblxThAqcTCt8rrncxxO5JAr...cjSsn6gRQ2b"
}
希望这会有所帮助!
【讨论】:
我在我的解决方案中使用 OWIN,因此在用户允许您的应用程序使用 LinkedIn 凭据后,向 URL https://api.linkedin.com/v1/people/~:(picture-URL)?format=json 发送一个简单明了的 GET 请求,如前所述,请求标头中带有不记名授权,解决了我的问题。
我的 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);
我在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;
}
最后是我使用上述方法的操作的 sn-p:
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);
...
}
我希望它可以帮助。 最好的问候
【讨论】:
这对我很有效!
解释-
这是包含所有其他数据的缩略图-
https://api.linkedin.com/v1/people/~:(id,location,picture-urls::(original),specialties,public-profile-url,email-address,formatted-name)?format=json
这是包含所有其他数据的原始图像 -
https://api.linkedin.com/v1/people/~:(id,location,picture-url,specialties,public-profile-url,email-address,formatted-name)?format=json
只需使用picture-urls::(original)而不是picture-url!
目前在Gradbee中使用
【讨论】:
https://apigee.com/console/linkedin
当您登录linkedin时,您将获得accesstoken。使用该访问令牌,您可以检索用户数据
LinkedInApiClient client = factory.createLinkedInApiClient(accessToken);
com.google.code.linkedinapi.schema.Person person = client.getProfileForCurrentUser(EnumSet.of(
ProfileField.ID, ProfileField.FIRST_NAME, ProfileField.LAST_NAME, ProfileField.HEADLINE,
ProfileField.INDUSTRY, ProfileField.PICTURE_URL, ProfileField.DATE_OF_BIRTH,
ProfileField.LOCATION_NAME, ProfileField.MAIN_ADDRESS, ProfileField.LOCATION_COUNTRY));
String imgageUrl=person.getPictureUrl();
【讨论】:
如果您的目标只是在您的网站上显示照片,那么 LinkedIn Member Profile Plugin 可能适合您。它将显示照片、一些附加信息以及 LinkedIn 品牌。
由于 LinkedIn API 旨在仅代表 current logged in user 使用,因此它不提供与 facebook graph api 类似的功能。
【讨论】:
这是我的解决方案,效果非常好:
def callback(self):
self.validate_oauth2callback()
oauth_session = self.service.get_auth_session(
data={'code': request.args['code'],
'grant_type': 'authorization_code',
'redirect_uri': self.get_callback_url()},
decoder=jsondecoder
)
me = oauth_session.get('people/~:(id,first-name,last-name,public-profile-url,email-address,picture-url,picture-urls::(original))?format=json&oauth2_access_token='+str(oauth_session.access_token), data={'x-li-format': 'json'}, bearer_auth=False).json()
social_id = me['id']
name = me['firstName']
surname = me['lastName']
email = me['emailAddress']
url = me['publicProfileUrl']
image_small = me.get('pictureUrl', None)
image_large = me.get('pictureUrls', {}).get('values', [])[0]
return social_id, name, surname, email, url, image_small, image_large, me
【讨论】:
这可能不是您所要求的,但它对个人调查很有用。
在 Firefox 中调用页面,左键单击背景图像上方的菜单。 选择检查元素(Q)。
搜索 -target-image" 这将是 img 元素中 id 属性的结尾。 该 img 元素的 src 属性将是背景图片的 URL。
【讨论】:
对我来说这是可行的
image= auth.extra.raw_info.pictureUrls.values.last.first
使用omniauth-linkedin gem
【讨论】: