Get Facebook user profile picture before application authentication

Summary:

I am working on a site that connects to Facebook through the Graph API. I was asked if I can get a user profile picture if they have already logged into Facebook, but before the user authenticates the application. Is it possible?

EDIT: I know that you can get a profile picture of people by going to http://graph.facebook.com/USERNAME_OR_USERID/picture?type=large , but can I get a username or user ID if they are logged in to Facebook, but didn’t allow my application?


Details:

According to the Facebook API user documentation , you can get your Facebook ID without access_token, and I know that if you go directly to the / me user, you can see their basic information. With a Facebook id, I can capture their pic profile.

However, when I try to call it from a website using the following code, I get an OAuthException.

 FB.api('/me', function(response) { console.log(response); }); 

I assume that they should authenticate the application, but I'm looking to see if I can skip the way to get their pic profile.

Thank you for your help!

+7
source share
4 answers

You can get all Facebook profile images without authentication.

You just call http://graph.facebook.com/USERID/picture?type=large . This URL redirects you to the image URL.

Edit: a query by username is no longer allowed, so I updated USERNAME_OR_USERID as USERID .

+7
source

yes you can get ..

 http://graph.facebook.com/naseer.panhwer/picture?type=normal http://graph.facebook.com/naseer.panhwer/picture?type=small http://graph.facebook.com/naseer.panhwer/picture?type=large 
+2
source

You can create an access token using the application identifier and secret, as follows:

https://graph.facebook.com/oauth/access_token?client_id= {appID} & client_secret = {appSecret} & grant_type = client_credentials

NOTE. Do not do this on the client side, as you run the risk of getting a capture on your application.

The resulting token can be a user to query users with the chart API without an invitation to enter.

0
source

How to get FB images without using or access tokens:

I tried to get only images of several members, but I got stuck and then wrote this snippet and worked for me,

HTML tag

 <img src="getFbImage.php?id=<fbid_of_the_person>&type=[small|large]" /> 

PHP code

 <?php $remoteImage = !isset($_GET['id']) ? "../images/default.png" : getImg($_GET['id']); $imginfo = getimagesize($remoteImage); header("Content-type: ".$imginfo['mime']); readfile($remoteImage); function getImg($id){ $dom = new DOMDocument; $dom->loadHTML(getData($id)); $tags = $dom->getElementsByTagName('img'); $img = ''; foreach ($tags as $tag) { $img =$tag->getAttribute('src'); if($img=='') continue; else if(isset($_GET['type']) && $_GET['type']=='large') break; } //This iteration has a lot of images try your luck. return $img; } function getData($id){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'https://www.facebook.com/photo.php?fbid='.$id); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 Firefox/39.0'); $data = curl_exec($ch); curl_close($ch); return $data; } ?> 

I just had to use a 30x30 image, and I got what I wanted. Also check that you also get a large image.

Hooray! Joy

0
source

All Articles