-2

I'm new to PHP and I have developed a system that automatically applies a watermark to a manually uploaded image. What I want to do is have a user sign in with their Facebook account, have the PHP get their profile picture from graph.facebook.com and then save it on my server under the /images directory.

I've been trying to do this for the past 4 and a half hours but I have no idea what i'm doing. I've tried to use Facebook's User Picture SDK but i have no idea how to apply it (clearly just copying and pasting isn't going to work haha). If someone could please provide me with some code, you certainly be mentioned on the final page.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Bradley
  • 132
  • 3
  • 15

2 Answers2

2

To show image in page

<img src="//graph.facebook.com/{{fid}}/picture">

To save

$image = file_get_contents('https://graph.facebook.com/'.$fid.'/picture?type=large');
$dir = dirname(__file__).'/avatar/'.$fid.'.jpg';
file_put_contents($dir, $image);

Facebook Graph API

http://graph.facebook.com/abdulla.nilam/picture

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

You can use graph API to get user's image

https://graph.facebook.com/v2.2/USER_ID/picture?width=500&height=500

USER_ID will be user's Facebook ID. You can set the width and height as required.

Samir Selia
  • 7,007
  • 2
  • 11
  • 30