无法获取fb用户的个人资料图片

时间:2012-08-18 16:21:21

标签: php facebook user-profile

我想将用户的个人资料照片放在另一个图像上,我尝试按照代码检索用户个人资料照片

$url='https://graph.facebook.com/'.$uid.'/picture?type=large';
$userpic = imagecreatefromjpeg($url);
imagejpeg($userpic, "xyz.jpg", 100);

但是我收到了这个错误:

imagecreatefromjpeg() [function.imagecreatefromjpeg]: Cannot read image data in /home/a3111484/public_html/fb/index.php

我也试过了file_get_contents(),但在这种情况下只会创建一个空的jpg文件。

请帮我弄清楚问题所在。

我也尝试过cURL方式,但是出现了这个错误:

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a3111484/public_html/fb/index.php on line 31

1 个答案:

答案 0 :(得分:0)

我认为这将满足您的需求:

<?php
$q = $_GET['q'];
$img = imagecreatefromstring(file_get_contents('https://graph.facebook.com/'.$q.'
   /picture?type=large'));
Header( "Content-type: image/jpeg");
imagejpeg($img);
imagedestroy($img);

它以facebook_img.php身份存在于我的网站上。

我使用它来使用以下代码将图像添加到页面中:

printf('<meta property="og:image" content="/path/to/facebook_img.php?q=%s" />', $fb_user_id);

@IMSoP:你需要做一些这样复杂的事情,因为id/picture API端点会返回301重定向到照片网址。

相关问题