简体   繁体   中英

How to fetch a user's profile Picture from Facebook?

This is the PHP ode I am using

<?php
session_start();
  include_once "fbconfig.php";
   if($_SESSION["loggedin"] && file_exists("images/dp/$_SESSION[email].jpg"))
    echo "<img src=\"images/dp/$_SESSION[email].jpg\" width=\"100px\">";
?>

This is the line to display the image

<img class="user_img" src="\images/dp/$_SESSION[email].jpg\" width=\"100px\">

Here is the code to fetch other user information

$user_profile = $facebook->api('/me');
  $fbid = $user_profile['id'];                 // To Get Facebook ID
    $fbuname = $user_profile['username'];  // To Get Facebook Username
  if(empty($fbuname))
    $fbuname = $user_profile['name']; // To Get Facebook full name
    $femail = $user_profile['email'];    // To Get Facebook email ID
  checkuser($fbid,$fbuname,$femail,'fb');    // To update local DB
  $_SESSION['userId'] = $fbuname;

This way the image does not appear where it should? Where am i going wrong?

add prefix http:// in img source. ie src="http://graph.facebook.com/$fbid/picture"

or use the following

$profile_pic = "https://graph.facebook.com/$fbid/picture";

so, img src=" '.$profile_pic.' " src=" '.$profile_pic.' "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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