Facebook Graph API用PHP拍照

时间:2012-09-28 14:45:21

标签: php facebook facebook-graph-api

我试图使用图形api拍摄用户的个人资料照片,我采用名字,电子邮件,fb id为真,但我没有拍摄用户的个人资料图片,尝试了所有内容并阅读了所有内容但失败了。

在与Facebook连接后,它在我的网站的个人资料图片区域的照片区域显示了一个大问号..

temp_fb_id参数也没有问题,它的插入也是真的

这是我的代码:

// above is the part with sessions getting user id, user email exc.
// $temp_fb_id is the variable that i use for taking the info for user name exc and its working but with photo part, not working , 
 //  img src is showing https://graph.facebook.com//picture?type=square,with a output, big question mark

 $first_name = $user->first_name;
 $last_name = $user->last_name;

 $photo = "https://graph.facebook.com/{$temp_fb_id}/picture?type=square";
 $photothumb = "https://graph.facebook.com/{$temp_fb_id}/picture?type=normal";
 $photolarge = "https://graph.facebook.com/{$temp_fb_id}/picture?type=large";


try {
$fb_insert = "INSERT INTO `members`(`first_name`, `photo_small`, `photo_thumb`, `photo`, `last_name`, `fb_id`) VALUE(:first_name, :photo, :photothumb, :photolarge, :last_name, :temp_fb_id)";
 $fb_insert_do = $db->prepare($fb_insert);
 $fb_insert_do->bindParam(':first_name', $first_name, PDO::PARAM_STR);
 $fb_insert_do->bindParam(':last_name', $last_name, PDO::PARAM_STR);
 $fb_insert_do->bindParam(':photo', $photo, PDO::PARAM_STR);
 $fb_insert_do->bindParam(':photothumb', $photothumb, PDO::PARAM_STR);
 $fb_insert_do->bindParam(':photolarge', $photolarge, PDO::PARAM_STR);
 $fb_insert_do->execute();
 }

 catch(PDOException $e) {
            /* catch and log errors over here. */
        }

谢谢

1 个答案:

答案 0 :(得分:0)

听起来您传递的用户ID由于某种原因不正确。您应该将$user->id的结果与$tmp_fb_id中存储的结果进行比较,以确保值相等。您应该可以将其中一个网址粘贴到src标记的img中,然后让它呈现照片。您也可以使用$user->username替换ID,看看它是否更好。

一个问题:为什么要将这些URL存储在数据库中,而不是在运行时从存储的Id中生成它们?如果Facebook决定在未来更改网址方案以获取个人资料照片,而不是仅仅几行代码,则必须更新所有数据库记录。