How can I display the users profile pic using the facebook graph api?

前端 未结 9 601
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 07:24

I would like to display the users profile picture inside of my applications canvas page, is there a way to do that using the graph api?

I know I can do it using FBML

相关标签:
9条回答
  • 2020-12-02 07:39
      //create the url
      $profile_pic =  "http://graph.facebook.com/".$uid."/picture";
    
     //echo the image out
     echo "<img src=\"" . $profile_pic . "\" />"; 
    

    Works fine for me

    0 讨论(0)
  • 2020-12-02 07:49

    to get different sizes, you can use the type parameter:

    You can specify the picture size you want with the type argument, which should be one of square (50x50), small (50 pixels wide, variable height), and large (about 200 pixels wide, variable height): http://graph.facebook.com/squall3d/picture?type=large.

    0 讨论(0)
  • 2020-12-02 07:55

    I was having a problem fetching profile photos while using CURL. I thought for a while there was something wrong my implementation of the Facebook API, but I need to add a bit to my CURL called:

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    
    0 讨论(0)
  • 2020-12-02 07:56

    Here is the code that worked for me!

    Assuming that you have a valid session going,

    //Get the current users id
    $uid = $facebook->getUser();
    
    //create the url
    $profile_pic =  "http://graph.facebook.com/".$uid."/picture";
    
    //echo the image out
    echo "<img src=\"" . $profile_pic . "\" />";
    

    Thanx goes to Raine, you da man!

    0 讨论(0)
  • 2020-12-02 07:57

    Knowing the user id the URL for their profile picture is:-

    http://graph.facebook.com/[UID]/picture
    

    where in place of [UID] you place your $uid variable, and that URL can be passed to flash

    0 讨论(0)
  • 2020-12-02 07:58

    The returned data is the binary data of the image type. If you use JavaScript to retrieve the user photo, please get the photo data as blob type in a XMLHttpRequest, and then retrieve the blob URL from the response. For your reference:

     var request = new XMLHttpRequest;
     var photoUri=config.endpoints.graphApiUri + "/v1.0/me/photo/$value";
     request.open("GET",photoUri);
     request.setRequestHeader("Authorization","Bearer "+token);
     request.responseType = "blob";
     request.onload = function (){
            if(request.readyState == 4 && request.status == 200){
                   var image = document.createElement("img");
                   var url = window.URL || window.webkitURL;
                   var blobUrl = url.createObjectURL(request.response);
                   image.src = blobUrl;
                   document.getElementById("UserShow").appendChild(image);
            }
     };
     request.send(null); 
    
    0 讨论(0)
提交回复
热议问题