简体   繁体   English

如何使用PHP获取Facebook个人资料照片?

[英]how to I get the Facebook profile photo with PHP?

I am trying to get the user's current profile photo... 我正在尝试获取用户的当前个人资料照片...

can anyone assist over here? 有人可以在这里协助吗?

thanks !! 谢谢 !!

Not specific to PHP, but the user's profile picture is public, so if you have the users facebook ID, just request: 不特定于PHP,但是用户的个人资料图片是公开的,因此,如果您具有用户facebook ID,则只需请求:

http://graph.facebook.com/user-id/picture http://graph.facebook.com/user-id/picture

More info on: http://developers.facebook.com/docs/reference/api 有关更多信息: http : //developers.facebook.com/docs/reference/api

try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');

    $updated = date("l, F j, Y", strtotime($me['updated_time']));

    echo "Hello " . $me['name'] . "<br />";
    echo "You last updated your profile on " . $updated  . "<br />" ;
    echo "<img src='https://graph.facebook.com/".$uid."/picture'/>"; 
}//end try getUser 
catch (FacebookApiException $e) {
    echo "Error:" . print_r($e, true);
}//end catch getUser 

I wrote this library a few months ago. 我几个月前写了这个库。

All you need is the user's email address, if it's public, it will fetch his profile picture. 您所需要的只是用户的电子邮件地址,如果是公开的,它将获取其个人资料照片。

It's super easy to use, you can grab it from here... 它非常易于使用,您可以从这里抓取...

https://github.com/shlomnissan/profilepicgrabber https://github.com/shlomnissan/profilepicgrabber

    <?php
      require '../src/profilepicgrabber.php';
      $pic_grabber = new ProfilePicGrabber('contact@snissan.me');
    ?>

    <h3>Facebook: </h3>
    <p><img src="<?php echo $pic_grabber->facebook(); ?>" /></p>

If you need the picture in different resolutions and with metadata you can check out this answer 如果您需要不同分辨率和元数据的图片,可以查看此答案

facebook connect - get profile photo in high/original resolution facebook connect-以高/原始分辨率获取个人资料照片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM