Building Twitter profile image url with Twitter user id

前端 未结 10 1694
日久生厌
日久生厌 2020-12-04 18:06

Is there any way of building a profile image url with user id or screen name? I store user ids in database but i don\'t want to store profile image url.

edit

10条回答
  •  星月不相逢
    2020-12-04 18:28

    Well I'm using a tricky way via PHP Dom Parser

    include('simple_html_dom.php');
    $html = file_get_html('http://twitter.com/mnckry');
    $img = array();
    
    foreach($html->find('img.size73') as $e)
        $img[] = $e->src;
    
    foreach($html->find('.profile-header-inner') as $e)
        $img[] = str_replace("')", "", str_replace("url('", "", $e->{'data-background-image'}));
    
    
    
    echo $img[0];//Avatar
    echo "
    "; echo end($img);//ProfileBG

    This will give you something like this; https://pbs.twimg.com/profile_images/378800000487958092/e04a191de329fcf8d000ca03073ad594_bigger.png

    to get 2 other size; for big version remove, "_bigger" for smaller version replace "_bigger" with "_normal"

提交回复
热议问题