简体   繁体   中英

How to get a Facebook user's profile picture in php

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.

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

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.

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