2011-12-26 118 views
0

我想下载Facebook个人资料图片的Facebook应用程序。为此,我在$uid中获得Facebook用户名/ ID的值。 echo $uid正显示出正确的结果,但是当我在下面的代码中使用它,它不是拿起值:

echo $uid; 
$imgDestinationPath = 'pic.jpg'; 
$link = 'http://graph.facebook.com/$uid/picture?type=large'; 
$content = file_get_contents($link); 
file_put_contents($imgDestinationPath, $content); 
error_reporting(E_ALL); 

而且,当我把代替$uid Facebook的用户名,它下载的图片即可。 请帮忙。我是PHP新手。

+0

附加使用error_reporting(E_ALL);到代码的开头,并寻找错误 – 2011-12-26 12:13:54

回答

1

,请使用 “” 在此声明

$link = "http://graph.facebook.com/$uid/picture?type=large"; 

就能解决问题

+0

感谢您的帮助..我还有一个问题。请看到它[链接](http://stackoverflow.com/questions/8633912/download-help-facebook-app) – Anurag 2011-12-26 12:28:14

1

$ UID没有得到评估,试试这个:

$link = 'http://graph.facebook.com/'.$uid.'/picture?type=large'; 

,或者你可以做到这一点带双引号:

$link = "http://graph.facebook.com/$uid/picture?type=large"; 

我宁愿第一个解决方案。这使得我的代码更易读。

+0

感谢您的帮助..我有一个更多的问题为好。请参阅它http://stackoverflow.com/questions/8633912/download-help-facebook-app – Anurag 2011-12-26 12:41:46