How to get company logo from Linkedin API?
Asked Answered
U

3

12

I made a mock company profile on Linkedin & have uploaded two images (see screenshot at bottom of question) and I'm trying to get the second image (large).

I can get the first image using both the logo-url and square-logo-url from the list of Company Profile fields in the Linkedin docs. The info I get back looks like this:

{
    'logoUrl': 'https://media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAagAAAAJDMwYzRhOGVmLWU3MzUtNGUyNi05YTgzLWU3MzVhOGViNGYyZA.png',
    'squareLogoUrl': 'https://media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAS6AAAAJDI4ODQ4NTgxLTQzZGQtNDEzZi1iZjIwLWNiNDgxZTk2NmE5ZA.png',
    'description': "Bla bla",
    etc. etc.
}

The links logoUrl and squareLogoUrl are linked to a square version of the first image.

Does anybody know how I can get the larger image from the Linkedin API? All answers are welcome!

enter image description here

Urion answered 12/1, 2016 at 16:45 Comment(2)
Hi Kramer, the LinkedIn developer API is a little tricky for getting started because of getting OAuth 2.0 permissions up. I started using Apigee to access it (tinyurl.com/grgzzqc). However, I tried to access your mock ZTMT company page (api.linkedin.com/v1/companies/9502799?format=json) but got back a 403 Forbidden response. Any advice on how I can start to play with this API?Bussey
@JonathanThoms - To make use of the Linkedin API you need to create a Linkedin app on linkedin.com/developer/apps and use the Authentication Keys you get to call the API. I'm not sure how Apigee works, I've shortly tried messing with it just now, but I can't get that to work either. I simply built OAuth2 in my website using Python. Sorry to not have an answer on that. I'll try to get that to work later and if I get it to work I'll let you know! Already a big thanks for trying to help me, I really really need to get this to work..Urion
P
4

It is linking to two separate images (the names are not the same). So what I would do is to look at the width and height parameters and see if that is what they are using to make the two images look different. So the first image is say 100x100 but the second is 600x200. Or they might be using one image but the dimensions are different.

I just visited the link you provided. Note the following:

logo-url

URL for the company logo in JPG format.

Your example logo-url says it is PNG.

JPEG(JPG) is used because it doesn't give you jaggies if you increase the size of the image.

Update: Ugh. I looked for some kind of a problem and the answer was right in front of me. Just bring up the page, right-click on the large image, and select "Save Image As..." from the pop-up menu. Since this DOES get you the right image you may have to scrape the HTML source code to find the right image each time (if you are going to do this for multiple companies).

enter image description here

Ok - took me a while to refind the web page you show...

Here is a PHP script that will extract the larger logo for you. All you have to do is to get TO the web page you need to extract it from:

<?php

    $a = file_get_contents( "ztmt.htm" );
    $a = str_replace( chr(13), "", $a );
    $a = str_replace( "<", "\n<", $a );
    $b = explode( "\n", $a );

    foreach( $b as $k=>$v ){
        if( preg_match("/hero-img/i",$v) ){
            $c = explode( " ", $v );
            foreach( $c as $k1=>$v1 ){
                if( preg_match("/\s+src\s*=/i", $v1) ){
                    $d = explode( "=", $v1);
                    $loc = substr( $d[1], 1, -1 );
                    echo "You can get the image from\n\n$loc\n";
                    }
                }
            }
        }
?>

As you can see, I downloaded the HTML source code that displays the web page (you can do that in one line in PHP), it then yanks in the HTML, breaks it up to one HTML command per line, looks for the "hero-img" line, gets the path to that image, and prints it out.

All you have to do is to write a little PHP that sends what company you are looking for to LinkedIn, go to that web page, suck the HTML off (which file_get_contents will do also), and then let the script yank the information out of that web page for you. This DOES NOT fix LinkedIn's mucked up information - it just bypasses it.

As my wife tells her kids at school - When you come to a problem build a bridge and get over it. LinkedIn won't respond - so just grab what you need off of their web pages.

Hopefull this wins me my green checkmark! :-)

BTW: This is called "hero-img" - have you looked to see if there is a tag named that? Just a random thought there. I know it isn't listed - but maybe LinkedIn is as bad about keeping their documentation updated as they are about responding to requests. :-/

I'd also check "hero-url" since everything else is "-url". Just a thought.

Philology answered 12/1, 2016 at 16:54 Comment(18)
I know the links are different, but they are simply separate versions of the same square image (not the wider image). I know it says in the link I provided that it should be a jpg image, but clearly, it is not. Any idea how I can get the larger image?Urion
Ok - this is way too simple. :-) Just bring up that web page, right-click on the large image, and select "Save Image As..." and save it. I just downloaded it. The filename is :AAEAAQAAAAAAAAXRAAAAJDE4YjhjZDI3LWRkMTQtNGEwNi1iMTIxLTVmY2U2NmUxNTQ3MA.png" Which is weird since they say it is supposed to be in jpeg format. What can I say? Looks like if you wanted to automate this to get other company's logos you may have to scrape the source code for the right file. :-/ By the way - don't forget to mark me as having the right answer! It will counteract the -1 I got earlier. :-)Philology
I understand it is simple with a browser. But the idea is that I can do it programmatically using the Linkedin API. I can't be manually going to the company page of all the users of my website.Urion
Well, not to nit pick but your request was just "Does anybody know how I can get the larger image?" and not "...via LinkedIn." :-) As per my suggestion though, there are only two ways to find out. The first is to contact LinkedIn and ask them why that particular logo isn't pointing to the right logo, and two - automate going to the company's web page for LinkedIn and scraping the HTML source code for the right image. This is a problem for LinkedIn and not Stack Overflow. Stack Overflow has no say so in what LinkedIn does. Got it?Philology
On developer.linkedin.com/support you can read that Linkedin actually redirects people with questions about their API to Stackoverflow, which is why I ask it here.Urion
Ugh. A Catch-22. Ok - let me go see if I can find someone there to help. BTW - I don't work for Stack Overflow. :-)Philology
Ok. I just logged in to LinkedIn and left feedback asking someone at LinkedIn's business unit to look at this question and help you. Hopefully they come by here soon.Philology
I really appreciate your efforts. I just built a proof of concept including automated login (otherwise you can't access the page) using PhantomJS and Selenium, which seems to work. The problem with scraping as opposed to getting the information from the api is that scraping is not only slow and not very scalable, I also don't know if it is allowed by the linkedin terms and conditions. You need to be logged in to access the page and if I do this a 1000 times per day I can imagine that linkedin will block my linkedin account. Therefore I would still greatly prefer a way to do this using the API.Urion
Mark! Just a question; you said you left feedback asking someone at Linkedin's business unit to look at this question. May I ask where you left that feedback? One of the most annoying things for me is that there seems to be no other way of contacting Linkedin, other than posting questions here on Stackoverflow. So any tips on connecting to someone from Linkedin is very welcome!Urion
@Urion - When you log in, click on the HOME link. The look to your right. First colujmn on the right at the bottom. TO:AlexNolasco - Thank you! (Did you know that Stack Overflow won't let you tag more than one person in a comment?Philology
PS - I always use regexp to parse html. :-)Philology
@Urion - I just had another idea - cache the web pages you have already been to. If another request comes in - just use your cache. Or better yet - just keep the image you need and make a directory with those images. In this way - you will slowly but surely cease asking for any web page. :-)Philology
You mean downloading the interwebs to my computer? ;-) But seriously; thanks to your suggestions I now created an automated scraper which even though it is not the official way, seems to work pretty ok. I'll add my code to your answer later so that others searching for the same can get it to work as well. Because I needed to do some trickery to get it to work.. :-)Urion
@Urion : I think all you really need to keep would be the company's name, the web page URL and the link to the image they are using (or something like just the word FALSE if there isn't an image available). In this way, (since you are doing a web page scraper) all you need to do is to look up the company's name in your table, maybe also check to make sure the request is still the same URL, and then just go get the image again (or - just download the image and store it as a base64 text field). Your concern was too many downloads from LinkedIn. This is how you get around that.Philology
@Urion : An update to the above - you should, once a day, always allow a single update to your information. So like keep the last date for update and when the dates don't match - do an actual update of your information. Again, if done right - Linked In won't mind the load (like at midnight your time). Also, in today's world with multi-terrabyte disk drives - what's a few hundred bytes or even kilobytes or megabytes? You could probably put 90% of all requests on your disk drive and not use over 100GB. Most logos are just not that big.Philology
@Urion : By the way - since you said you wrote a scraper - do I get my big green checkmark for the right answer? It is the only way you go up the ladder at Stack Overflow. :-)Philology
In your scraping story you're missing that I'm scraping from a headless server, which means that I need to automate logging in, and because you're signing in from an "untrusted location" linkedin also asks for verification using a pin code they send to your email. Solving all that took a little more than you mention :-) . And about your green checkmark. Since I really want to do this via the official/API way, I'm waiting a little more today if someone comes up with a brilliant API way of doing things. If not (wichi is very likely), you'll get your green checkmark :-)Urion
@Urion : ok! Thank you! :-)Philology
D
1

You cannot do it, becuase the second image depends on how that company designed its page on linkedin.

A company with out second large image,

https://www.linkedin.com/company/ztrdg

A company with second large image as it is not a logo,

https://www.linkedin.com/company/ibm

So that image (large one) is not managed by linkedin, of course you cannot get it from linkedin's api.

The only thing you can do is that resize the logo with a good image library. I suggest the imgscalr in java.

If you want to get big image when it exists, you can use the company url, and get whole html document, then find the url which is in top-image class. And a piece of code:

Document  docu = Jsoup.connect(companyUrl).
            timeout(TIMEOUT).
            userAgent(CRAWLER_NAME).
            get();
Elements elements = document.getElementsByClassName("top-image");
Descendant answered 20/1, 2016 at 17:59 Comment(1)
I know it is optional, but it is still managed and hosted by Linkedin. When you create a company page on Linkedin it is simply a standardised upload field. So, it is definitely possible for linkedin to create an API for it. But I'm starting to doubt if they did.Urion
B
0

I did a little digging but I can't figure out how on my own. However, I found a thread on this subject that may be useful - but I'm not authorized to look at it, but seems to be for your exact issue. As an active coder for the Developer API, you may have permission. The link is to a forum page and you should see a link to a question titled "Requesting company hero image through API". Let me know if it helps.

Bussey answered 20/1, 2016 at 5:35 Comment(3)
Hi Thomas. Thanks for the link. Unfortunately I don't seem to have access either. The latest thread on that forum is from 2014, which makes me think they closed that whole forum all together in favor of giving support through Linkedin (Linkedin Support people, where art thou?!). If anyone else has access to those forums. I'd be happy to know! The title suggests that the feature didn't exist back then, so I'm starting to be afraid that they still didn't do anything to implement it.. :-( But thanks for trying to help out!Urion
I have the standard privileges there. When I saw this I was interested to know if they had the right answer - but like you - I can't look at it either. :-(Philology
Ha. I don't think anybody can. Apart from scraping I don't know how you would solve this.Bussey

© 2022 - 2024 — McMap. All rights reserved.