php – 网站上的FB登录集成

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 网站上的FB登录集成脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试整合FB登录网站.我现在能够登录但是现在我无法理解如何打印邮件ID和用户名.

请帮助.我是这一切的新手.

这是我正在使用的代码

<?PHP 
session_start();
require_once "C:/xampp/htdocs/uttam/src/faceBook.PHP"; 

$config = array(
    "appId" => '<removed>',"secret" => '<removed>');

$fb = new Facebook($config);

$user = $fb->getUser();

?>  

<htML> 
 <head> 
  <tITle>Hello Facebook</title> 
 </head> 
 <body>
<?PHP
if (!$user) { 
    $params = array(
        "scoPE" => "read_stream,publish_stream,user_photos","redirect_uri" => 'http://localhost/uttam');
    echo '<a href="' . $fb->getLoginUrl($params) . '">LOGin</a>'; 
}
else { 
?>
  <form action="<?PHP echo $_SERVER["PHP_SELF"];?>" method="post" enctype="multipart/form-data">
   <textarea name="message" id="message" rows="2" cols="40"></textarea><br>
   <input type="file" name="image" id="image"><br>
   <input type="submit" value="Update"> 
  </form> 
<?PHP
    // PRocess form submission
    if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_POST["message"])) {
        if (is_uploaded_file($_FILES["image"]["tmp_name"])) { 
            $finfo = finfo_open(FILeiNFO_MIME_TYPE);
            $mime = finfo_file($finfo,$_FILES["image"]["tmp_name"]);
            $Allowed = array("image/gif","image/jpg","image/jpeg","image/png");
            // upload image
            if (in_array($mime,$allowed)) { 
                $data = array(
                    "name" => $_POST["message"],"image" => "@" . realpath($_FILES["image"]["tmp_name"]));
                $fb->setFileUploadSupport(true); 
                $status = $fb->api("/me/photos","POST",$data);    
            }
        }
        else {
            // update status message
            $data = array("message" => $_POST["message"]);
            $status = $fb->api("/me/Feed",$data); 
        }
    } 
    if (isset($status)) {
        echo "<pre>" . print_r($status,true) . "</pre>";
    } 
}
?>
 </body> 
</html>

解决方法

你最好在你的html中尝试javascript代码.试试这些 facebook link

对我来说它工作正常

代码中:function testAPI(){    console.log(‘欢迎!获取您的信息……’);    FB.api(‘/ me’,function(response){      console.log(“******获取完整响应******”JSON.stringify(响应)“********”);      document.getElementById(‘status’).innerHTML =        “感谢您登录,’response.name’!’;    });  }

脚本宝典总结

以上是脚本宝典为你收集整理的php – 网站上的FB登录集成全部内容,希望文章能够帮你解决php – 网站上的FB登录集成所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。