How to get company logo from Linkedin API?

后端 未结 3 2224
难免孤独
难免孤独 2021-02-20 00:51

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 g

相关标签:
3条回答
  • 2021-02-20 01:09

    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.

    0 讨论(0)
  • 2021-02-20 01:10

    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");
    
    0 讨论(0)
  • 2021-02-20 01:18

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

    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.

    0 讨论(0)
提交回复
热议问题