George Wiscombe
George Wiscombe

Reputation: 1422

Getting LinkedIn Profile Picture

Is there an easy way to grab a users LinkedIn profile photo?

Ideally similar to how you would with Facebook - http://graph.facebook.com/userid/picture

Upvotes: 54

Views: 102940

Answers (13)

digitalguy99
digitalguy99

Reputation: 549

I would like to recommend using the ScrapIn LinkedIn API which is by far the easiest method I have found as of today. Simply sign up for free and get your API key: Getting ScrapIn API Key

Then, simply send a GET request to https://api.scrapin.io/enrichment/profile?apikey=API_KEY&linkedinUrl=https://www.linkedin.com/in/PROFILE_ID/

(don't forget to replace API_KEY & PROFILE_ID(username) with respective values)

For example with Invoke-RestMethod on PowerShell:

$response = irm "https://api.scrapin.io/enrichment/profile?apikey=API_KEY&linkedinUrl=https://www.linkedin.com/in/PROFILE_ID/"

This will give you a $response with the following format:

{
  "success": true,
  "person": {
    "publicIdentifier": "williamhgates",
    "linkedInIdentifier": "ACoAAA8BYqEBCGLg_vT_ca6mMEqkpp9nVffJ3hc",
    "firstName": "Bill",
    "lastName": "Gates",
    "headline": "Co-chair, Bill & Melinda Gates Foundation",
    "location": "Seattle, Washington United States",
    "photoUrl": "https://media.licdn.com/dms/image/xxxxxxxxxx",
    "creationDate": {
      "month": 5,
      "year": 2013
    },
    "followerCount": 34903132,
    "connectionCount": 9,
    "positions": {
      "positionsCount": 3,
      "positionHistory": [
        {
          "startEndDate": {
            "start": {
              "year": 2000
            }
          },
          "title": "Co-chair",
          "companyName": "Bill & Melinda Gates Foundation",
          "companyLogo": "https://media.licdn.com/dms/image/xxxxxxxxxxxx",
          "linkedInUrl": "https://www.linkedin.com/company/8736/"
        },
        {
          "startEndDate": {
            "start": {
              "year": 2015
            }
          },
          "title": "Founder",
          "companyName": "Breakthrough Energy ",
          "companyLogo": "https://media.licdn.com/dms/image/xxxxxxxxxx",
          "linkedInUrl": "https://www.linkedin.com/company/19141006/"
        },
        {
          "startEndDate": {
            "start": {
              "year": 1975
            }
          },
          "title": "Co-founder",
          "companyName": "Microsoft",
          "companyLogo": "https://media.licdn.com/dms/image/xxxxxxxxx",
          "linkedInUrl": "https://www.linkedin.com/company/1035/"
        }
      ]
    },
    "schools": {
      "educationsCount": 2,
      "educationHistory": [
        {
          "startEndDate": {
            "start": {
              "year": 1973
            },
            "end": {
              "year": 1975
            }
          },
          "schoolName": "Harvard University",
          "schoolLogo": "https://media.licdn.com/dms/image/xxxxxxxxx",
          "linkedInUrl": "https://www.linkedin.com/company/1646/"
        },
        {
          "schoolName": "Lakeside School",
          "schoolLogo": "https://media.licdn.com/dms/image/xxxxxxxxxx",
          "linkedInUrl": "https://www.linkedin.com/company/30288/"
        }
      ]
    },
    "summary": "Co-chair of the Bill & Melinda Gates Foundation. Founder of Breakthrough Energy. Co-founder of Microsoft. Voracious reader. Avid traveler. Active blogger.",
    "skills": [
      
    ]
  },
  "company": {
    "websiteUrl": "https://www.gatesfoundation.org/about/careers",
    "name": "Bill & Melinda Gates Foundation",
    "logo": "https://media.licdn.com/dms/image/xxxxxxxxx",
    "employeeCount": 3509,
    "description": "We are optimists on a mission to create a world where every person has the chance to live a healthy, productive life. \n\nIn developing countries, the Bill and Melinda Gates Foundation focuses on improving people’s health and giving them the chance to lift themselves out of hunger and extreme poverty. In the United States, it seeks to ensure that all people—especially those with the fewest resources—have access to the opportunities they need to succeed in school and life. ",
    "tagline": "We are a nonprofit organization fighting poverty, disease, and inequity around the world.",
    "specialities": [
      "Global Health",
      "Global Development",
      "US Education",
      "Gender Equality"
    ],
    "headquarter": {
      "country": "US",
      "geographicArea": "WA",
      "city": "Seattle",
      "postalCode": "98109"
    },
    "industry": "Non-profit Organizations",
    "universalName": "bill-&-melinda-gates-foundation",
    "linkedinUrl": "https://www.linkedin.com/company/bill-&-melinda-gates-foundation/",
    "linkedinId": "8736"
  },
  "credits_left": 98950,
  "rate_limit_left": 19748
}

From there you can get the LinkedIn Profile Picture URL path by calling:

$response.person.photoUrl

Reference: https://www.scrapin.io/blog/linkedin-api#step-by-step-guide-to-linkedin-api-integration:~:text=Using%20ScrapIn%20LinkedIn%20API%20(Quick%20and%20Easy)

Upvotes: -2

Zain Ahmad Chattha
Zain Ahmad Chattha

Reputation: 79

You can get a user profile picture by just doing the below-defined steps.

Linked URL https://api.linkedin.com/v2/people/id=USER_ID?projection=(id,profilePicture(displayImage~digitalmediaAsset:playableStreams))

USER_ID: yjuMzBoycX // test userID.

Call this API to fetch the profile picture of the provided userId,

You will get the response Look like below, in the response, ProfilePicute -> elements -> identifiers -> identifier is the link to your user profile picture and will be accessible by just clicking on the link.

Sample Response. // test user profile picture. you will get four pictures with different resolutions in the element array.

{
"profilePicture": {
    "displayImage": "urn:li:digitalmediaAsset:C4D03AQEJkSP2gLg1aA",
    "displayImage~": {
        "paging": {
            "count": 10,
            "start": 0,
            "links": []
        },
        "elements": [
            {
                "artifact": "urn:li:digitalmediaMediaArtifact:(urn:li:digitalmediaAsset:C4D03AQEJkSP2gLg1aA,urn:li:digitalmediaMediaArtifactClass:profile-displayphoto-shrink_100_100)",
                "authorizationMethod": "PUBLIC",
                "data": {
                    "com.linkedin.digitalmedia.mediaartifact.StillImage": {
                        "orientation": "TopLeft",
                        "storageAspectRatio": {
                            "widthAspect": 1.0,
                            "heightAspect": 1.0,
                            "formatted": "1.00:1.00"
                        },
                        "storageSize": {
                            "width": 100,
                            "height": 100
                        },
                        "rawMetadataTags": [],
                        "scale": "DOWN",
                        "mediaType": "image/jpeg",
                        "rawCodecSpec": {
                            "name": "jpeg",
                            "type": "image"
                        },
                        "displaySize": {
                            "width": 100.0,
                            "uom": "PX",
                            "height": 100.0
                        },
                        "displayAspectRatio": {
                            "widthAspect": 1.0,
                            "heightAspect": 1.0,
                            "formatted": "1.00:1.00"
                        }
                    }
                },
                "identifiers": [
                    {
                        "identifier": "https://media.licdn.com/dms/image/C4D03AQEJkSP2gLg1aA/profile-displayphoto-shrink_100_100/0/1661232745172?e=1712188800&v=beta&t=bEUF4w6ndy7kaRDbq1Lyx1bRuZNHDL1FD7H-D6PAafY",
                        "index": 0,
                        "mediaType": "image/jpeg",
                        "file": "urn:li:digitalmediaFile:(urn:li:digitalmediaAsset:C4D03AQEJkSP2gLg1aA,urn:li:digitalmediaArtifactClass:profile-displayphoto-shrink_100_100,0)",
                        "identifierType": "EXTERNAL_URL",
                        "identifierExpiresInSeconds": 1712188800
                    }
                ]
            },
            {
                "artifact": "urn:li:digitalmediaMediaArtifact:(urn:li:digitalmediaAsset:C4D03AQEJkSP2gLg1aA,urn:li:digitalmediaMediaArtifactClass:profile-displayphoto-shrink_200_200)",
                "authorizationMethod": "PUBLIC",
                "data": {
                    "com.linkedin.digitalmedia.mediaartifact.StillImage": {
                        "orientation": "TopLeft",
                        "storageAspectRatio": {
                            "widthAspect": 1.0,
                            "heightAspect": 1.0,
                            "formatted": "1.00:1.00"
                        },
                        "storageSize": {
                            "width": 200,
                            "height": 200
                        },
                        "rawMetadataTags": [],
                        "scale": "DOWN",
                        "mediaType": "image/jpeg",
                        "rawCodecSpec": {
                            "name": "jpeg",
                            "type": "image"
                        },
                        "displaySize": {
                            "width": 200.0,
                            "uom": "PX",
                            "height": 200.0
                        },
                        "displayAspectRatio": {
                            "widthAspect": 1.0,
                            "heightAspect": 1.0,
                            "formatted": "1.00:1.00"
                        }
                    }
                },
                "identifiers": [
                    {
                        "identifier": "https://media.licdn.com/dms/image/C4D03AQEJkSP2gLg1aA/profile-displayphoto-shrink_200_200/0/1661232745172?e=1712188800&v=beta&t=nDPU4akewODGbgzUJxj4fupr7Xv66YbvLdIC89-WP4k",
                        "index": 0,
                        "mediaType": "image/jpeg",
                        "file": "urn:li:digitalmediaFile:(urn:li:digitalmediaAsset:C4D03AQEJkSP2gLg1aA,urn:li:digitalmediaArtifactClass:profile-displayphoto-shrink_200_200,0)",
                        "identifierType": "EXTERNAL_URL",
                        "identifierExpiresInSeconds": 1712188800
                    }
                ]
            },
            {
                "artifact": "urn:li:digitalmediaMediaArtifact:(urn:li:digitalmediaAsset:C4D03AQEJkSP2gLg1aA,urn:li:digitalmediaMediaArtifactClass:profile-displayphoto-shrink_400_400)",
                "authorizationMethod": "PUBLIC",
                "data": {
                    "com.linkedin.digitalmedia.mediaartifact.StillImage": {
                        "orientation": "TopLeft",
                        "storageAspectRatio": {
                            "widthAspect": 1.0,
                            "heightAspect": 1.0,
                            "formatted": "1.00:1.00"
                        },
                        "storageSize": {
                            "width": 400,
                            "height": 400
                        },
                        "rawMetadataTags": [],
                        "scale": "DOWN",
                        "mediaType": "image/jpeg",
                        "rawCodecSpec": {
                            "name": "jpeg",
                            "type": "image"
                        },
                        "displaySize": {
                            "width": 400.0,
                            "uom": "PX",
                            "height": 400.0
                        },
                        "displayAspectRatio": {
                            "widthAspect": 1.0,
                            "heightAspect": 1.0,
                            "formatted": "1.00:1.00"
                        }
                    }
                },
                "identifiers": [
                    {
                        "identifier": "https://media.licdn.com/dms/image/C4D03AQEJkSP2gLg1aA/profile-displayphoto-shrink_400_400/0/1661232745172?e=1712188800&v=beta&t=VQDb7KtpR5gT69eTuA8n0xuE_WYOJD5kkPgmXA_a7dM",
                        "index": 0,
                        "mediaType": "image/jpeg",
                        "file": "urn:li:digitalmediaFile:(urn:li:digitalmediaAsset:C4D03AQEJkSP2gLg1aA,urn:li:digitalmediaArtifactClass:profile-displayphoto-shrink_400_400,0)",
                        "identifierType": "EXTERNAL_URL",
                        "identifierExpiresInSeconds": 1712188800
                    }
                ]
            },
            {
                "artifact": "urn:li:digitalmediaMediaArtifact:(urn:li:digitalmediaAsset:C4D03AQEJkSP2gLg1aA,urn:li:digitalmediaMediaArtifactClass:profile-displayphoto-shrink_800_800)",
                "authorizationMethod": "PUBLIC",
                "data": {
                    "com.linkedin.digitalmedia.mediaartifact.StillImage": {
                        "orientation": "TopLeft",
                        "storageAspectRatio": {
                            "widthAspect": 1.0,
                            "heightAspect": 1.0,
                            "formatted": "1.00:1.00"
                        },
                        "storageSize": {
                            "width": 800,
                            "height": 800
                        },
                        "rawMetadataTags": [],
                        "scale": "UNCHANGED",
                        "mediaType": "image/jpeg",
                        "rawCodecSpec": {
                            "name": "jpeg",
                            "type": "image"
                        },
                        "displaySize": {
                            "width": 800.0,
                            "uom": "PX",
                            "height": 800.0
                        },
                        "displayAspectRatio": {
                            "widthAspect": 1.0,
                            "heightAspect": 1.0,
                            "formatted": "1.00:1.00"
                        }
                    }
                },
                "identifiers": [
                    {
                        "identifier": "https://media.licdn.com/dms/image/C4D03AQEJkSP2gLg1aA/profile-displayphoto-shrink_800_800/0/1661232745172?e=1712188800&v=beta&t=o1MXA1LurNoZwPsrZ_M5Uk65JvLjqo_Ta9LOPbj5dUo",
                        "index": 0,
                        "mediaType": "image/jpeg",
                        "file": "urn:li:digitalmediaFile:(urn:li:digitalmediaAsset:C4D03AQEJkSP2gLg1aA,urn:li:digitalmediaArtifactClass:profile-displayphoto-shrink_800_800,0)",
                        "identifierType": "EXTERNAL_URL",
                        "identifierExpiresInSeconds": 1712188800
                    }
                ]
            }
        ]
    }
},
"id": "yjuMzBoycX"

}

Upvotes: 0

diegosousa88
diegosousa88

Reputation: 91

I'm using OWIN in my solution so after the user allows your application to use LinkedIn credentials a simple and plain GET request to URL https://api.linkedin.com/v1/people/~:(picture-URL)?format=json, as explained before with a Bearer authorization in request headers, solved my problems.

My Startup.Auth.cs file

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);

My method to get the user's profile picture in 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;
}

And finally a snippet of my action that consumes the method above:

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);
   ...
}

I hope it could help. Best regards

Upvotes: 6

sparkle
sparkle

Reputation: 7390

For me this works

image= auth.extra.raw_info.pictureUrls.values.last.first

with omniauth-linkedin gem

Upvotes: 0

ccoloma
ccoloma

Reputation: 301

If you use the 2.0 version of the API (all developers need to migrate by March 1, 2019), you should use projections to expand the profilePicture.displayImage. If you do this, you will have a full JSON element displayImage~ (the '~' is not a typo) inside profilePicture with all the info you may need.

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

You can see more at the Profile Picture API doc to look at the JSON response or the Profile API doc.

Upvotes: 20

arora
arora

Reputation: 869

This works well for me!

Explained -

This is for a thumbnail with all other data-

https://api.linkedin.com/v1/people/~:(id,location,picture-urls::(original),specialties,public-profile-url,email-address,formatted-name)?format=json

This is for original image with all other data -

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

Just use picture-urls::(original)instead of picture-url !

This is currently being used in Gradbee

Upvotes: 4

piezzoritro
piezzoritro

Reputation: 141

This is my solution and it works very very well:

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

Upvotes: 1

Robin Hodson
Robin Hodson

Reputation: 1

This may not be quite what you're asking for, but it's useful for individual investigations.

Call up the page in Firefox, left-click the menu over the background image. Select Inspect Element(Q).

search for -target-image" That will be the end of of id attribute in an img element. The src attribute of that img element, will be the URL of the background image.

Upvotes: -1

Madan Sapkota
Madan Sapkota

Reputation: 26071

Once the Linkedin user authentication using OAuth 2.x is done, make a request to the people URL.

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

Where ~ stands for current authenticated user. The response will be something like this ...

{
  "id": "KPxRFxLxuX",
  "emailAddress": "[email protected]",
  "firstName": "John",
  "lastName": "Doe",
  "formattedName": "John Doe",
  "pictureUrl": "https://media.licdn.com/mpr/mprx/0_0QblxThAqcTCt8rrncxxO5JAr...cjSsn6gRQ2b"
}

Hope this helps!

Upvotes: 12

Hoodah
Hoodah

Reputation: 29

If your goal is simply to display the photo on your site then the LinkedIn Member Profile Plugin may work out for you. It will display the photo, some additional info, along with LinkedIn branding.

Since the LinkedIn API is designed to be used only on behalf of the current logged in user it does not offer similar functionality as the facebook graph api.

Upvotes: 0

Kimmi Dhingra
Kimmi Dhingra

Reputation: 2289

When you login to linkedin, you will get accesstoken. Use that access token and you can retrieve users data

 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();

Upvotes: 2

Adam Trachtenberg
Adam Trachtenberg

Reputation: 2241

Not as easy... You need to go through OAuth, then on behalf of the member, you ask for:

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

Upvotes: 35

Rahim Basheer
Rahim Basheer

Reputation: 521

You can retrieve the original photo size with this call:

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

Note that this could be any size, so you'll need to do scaling on your side, but the image is the original one uploaded by the user.

Upvotes: 52

Related Questions