Suganthan Raj
Suganthan Raj

Reputation: 1970

How to get facebook profile image using facebook username withou Oauth using facebook API

I have tried with this code. To get id (numeric) by facebook username (string) it returns nothing

     $fb = new Facebook\Facebook([
            'app_id' => $app_id,
            'app_secret' => $secret,
             'default_graph_version' => 'v2.2',
     ]);

    try {


    $request = new Facebook\FacebookRequest(
                             locale,
                             'GET',
                             '/10200410760947768',
                             array(
                               'fields' => 'picture.type(large)'
                             )
                       );

     $response = $request->execute();
     $graphObject = $response->getGraphObject();
     echo '<pre>';
     print_r($graphObject);
     echo '</pre>';
     /* handle the result */
     } catch(Facebook\Exceptions\FacebookResponseException $e) {
          // When Graph returns an error
         echo 'Graph returned an error: ' . $e->getMessage();
         exit;
     } catch(Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
       exit;
     }

I need to get profile picture when i give a input like Example: https://www.facebook.com/username/

By the above example i need a profile picture image url without Oauth Login

Upvotes: 0

Views: 439

Answers (1)

Segers-Ian
Segers-Ian

Reputation: 1057

You should be fine with just formatting the following URL:

https://graph.facebook.com/<FacebookUserExternalId>/picture?type=square

No authentication or anything required.

EDIT : My bad, I didn't see you needed to get the profile image based on the User name. Sorry, this won't work (my suggestion nor an alternative to achieve your goal). Facebook did this on purpose to increase the security and privacy.

Upvotes: 1

Related Questions