【问题标题】:Advice - User profile image from Facebook Graph API建议 - 来自 Facebook Graph API 的用户个人资料图片
【发布时间】:2016-02-11 15:44:57
【问题描述】:

我正在使用 codeigniter 构建一个应用程序,允许用户使用 Facebook Graph API 登录。

我正在存储用户信息并希望获得有关我应该如何处理用户个人资料图像的建议。

由于 API 提供了图像的 URL,我应该将其存储在本地并将文件名保存到 db 还是简单地将 URL 存储在另一列中?

在我看来,我正在显示存储的本地图像,如下所示:

 <img src="./image/avatars/<?php echo $user->profile ?>" class="img-circle" alt="" />

如果我将 FB URL 存储在另一列中,我可以添加一些条件来显示 $user->profile 是否为空。

类似:

  <?php if ($user->profile == null && $user->fbprofile != null){
                                echo "<img src='".$user->fbprofile."' class='img-circle' />";
                            }else{
                                echo "<img src='./image/avatars/".$user->profile."' class='img-circle'/>";
                            ?>

请注意,如果是普通用户,如果没有上传任何内容,他们将始终拥有个人资料图片,即 avatar.png。

对于这是否是处理此问题的最佳方法有什么建议吗?不确定对此的最佳做法是什么。

谢谢

【问题讨论】:

  • 从 FB 复制头像。并将其存储在/image/avatars/
  • 下载fb图片到你的文件夹

标签: php codeigniter facebook-graph-api


【解决方案1】:

在收到 Facebook 电子邮件和 FBID 后使用此代码

    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, 'http://graph.facebook.com/'.(FBID ).'/picture');
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($ch);
    curl_close($ch);
    $fileName = 'image/avatars/fbprofile_'time()'.jpg';
    $file = fopen($fileName, 'w+');
    fputs($file, $data);
    fclose($file);

和 "$fileName" 保存在您的数据库中作为配置文件 url

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-16
    • 2014-06-24
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    相关资源
    最近更新 更多