Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何正确使用facebook OAuth2?_Php_Javascript_Facebook_Oauth 2.0_Facebook Oauth - Fatal编程技术网

Php 如何正确使用facebook OAuth2?

Php 如何正确使用facebook OAuth2?,php,javascript,facebook,oauth-2.0,facebook-oauth,Php,Javascript,Facebook,Oauth 2.0,Facebook Oauth,在3天的拼命尝试将facebook登录系统集成到我的网站之后,我得出了一个结论,我惨遭失败。我只是用JavaScript-sdkapi调用创建了一堆PHP-SDK,结果正如预期的那样,不起作用 我在谷歌上搜索过其他人的问题、教程和解释的答案,但现在我承认自己失败了 你能给我一个很好的指导吗?或者你能给我一个关于他们图书馆东西的深入了解吗 希望这不会被关闭 编辑:这是使用facebook登录系统的推荐方法吗 编辑2: FB.init({ appId:“”,//应用程序仪表板中的应用程序ID cha

在3天的拼命尝试将facebook登录系统集成到我的网站之后,我得出了一个结论,我惨遭失败。我只是用JavaScript-sdkapi调用创建了一堆PHP-SDK,结果正如预期的那样,不起作用

我在谷歌上搜索过其他人的问题、教程和解释的答案,但现在我承认自己失败了

你能给我一个很好的指导吗?或者你能给我一个关于他们图书馆东西的深入了解吗

希望这不会被关闭

编辑:这是使用facebook登录系统的推荐方法吗

编辑2:

FB.init({
appId:“”,//应用程序仪表板中的应用程序ID
channelUrl:“//romeo.no ip.org/94seconds/channel.html”,//用于x域通信的通道文件
status:true,//在初始化时检查登录状态?
cookie:true,//设置会话cookie以允许服务器访问会话?
xfbml:true//是否解析此页面上的xfbml标记?
});

此代码在调用FB.init()之前生成调用的
FB.getLoginStatus()。

我的页面如下所示:

<!DOCTYPE html>
<html>
    <head>
        <script src="../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js"></script>
    </head>
    <body>
        <div id="fb-root"></div>
        <script>
          window.fbAsyncInit = function() {
                FB.init({
                  appId      : '<?php echo $core->appId; ?>', // App ID from the App Dashboard
                  channelUrl : '//romeo.no-ip.org/94seconds/channel.html', // Channel File for x-domain communication
                  status     : true, // check the login status upon init?
                  cookie     : true, // set sessions cookies to allow your server to access the session?
                  xfbml      : true  // parse XFBML tags on this page?
                });
          };

          // Load the SDK's source Asynchronously
          // Note that the debug version is being actively developed and might 
          // contain some type checks that are overly strict. 
          // Please report such bugs using the bugs tool.
          (function(d, debug){
             var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
             if (d.getElementById(id)) {return;}
             js = d.createElement('script'); js.id = id; js.async = true;
             js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
             ref.parentNode.insertBefore(js, ref);
           }(document, /*debug*/ false));
        </script>
    </body>
</html>

window.fbAsyninit=函数(){
FB.init({
appId:“”,//应用程序仪表板中的应用程序ID
channelUrl:“//romeo.no ip.org/94seconds/channel.html”,//用于x域通信的通道文件
status:true,//在初始化时检查登录状态?
cookie:true,//设置会话cookie以允许服务器访问会话?
xfbml:true//是否解析此页面上的xfbml标记?
});
};
//异步加载SDK的源代码
//请注意,调试版本正在积极开发中,可能
//包含一些过于严格的类型检查。
//请使用bug工具报告此类bug。
(功能(d,调试){
var js,id='facebook jssdk',ref=d.getElementsByTagName('script')[0];
if(d.getElementById(id)){return;}
js=d.createElement('script');js.id=id;js.async=true;
js.src=“//connect.facebook.net/en_US/all”+(debug?/debug):“)+”.js”;
ref.parentNode.insertBefore(js,ref);
}(文档,/*debug*/false));
编辑3:没关系,我刚刚意识到我花了3-4个小时在墙上打孔,因为我错放了一些代码。我把错误弄丢了D谢谢你们。

给你们,兄弟

  • 这会将fb js sdk添加到您的页面

    (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s);
        js.id = id;
        js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=" + APP_ID;
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
    
  • 这将通知您用户是否登录或当前状态

    window.fbAsyncInit = function() {
    
        // Additional init code here
        FB.getLoginStatus(function(response) {
            if (response.status === 'connected') {
                // logged in and connected
    
            } else if (response.status === 'not_authorized') {
            // not_authorized - the user has not authorized ur app
    
            } else {
            // User is not_logged_in
    
            }
        });
    
        FB.Event.subscribe('edge.create',
            function(response) {
                //Not relevant here
                //User has just liked your page
                //likeHandler(response);
            });
    };
    
  • 这是为了让用户登录

    function Login() {
        FB.login(function (e) {
            //        console.log(e.authResponse);
            if (e.authResponse) {
                M_access_token = e.authResponse.accessToken;
    
                //custom function to get user details
                get_details();
            } else {
            //            console.log("Error : Failed to Authorize")
            }
        }, {
            scope: "email,user_likes,publish_stream"
        })
    }
    
    //Notice the scope param above
    
  • 这是用于注销用户的

    function Logout() {
        FB.logout(function(response) {
            // user is now logged out
            });
    }
    
  • 自定义函数获取详细信息

    function get_details(typeCalled) {
        FB.api("/me?fields=name,id,email,gender,username,picture", function (e) {
            fbUserObject = e;
            //        M_user_id = e.id;
            //        M_user_full_name = e.name;
            //        M_user_email = e.email;
            //        M_user_gender = e.gender;
            //        M_username = e.username;
            //picture = e.picture.data.url;
        });
    }
    
  • 获得用户数据后,可以将其传递到服务器并设置会话。用户单击注销按钮后,应清除服务器上的会话


  • 祝你一切顺利!:)

    你能给我一个关于这份工作的好教程吗?
    直接让人们帮你用谷歌搜索。@tradyblix:不。只是问是否有人遇到过、制作过或是一次又一次地学习过。@hakre:你是在温和地建议我不要使用OAuth2吗?不,只是它有一些粗糙的边缘。在调用FB.init()之前,我一直在调用double
    FB.getLoginStatus()。调用FB.init()之前调用了all.js(第52行)FB.getLoginStatus()。
    error。在步骤1中,如果不提供APP_ID,则无法自动初始化,因此会出现上述错误。否则,您必须通过调用//init FB JS SDK FB.init(这里的参数)手动初始化它;老兄,你真是个天才。我成功了,这一切都是因为你。塔克斯!我活着就是为了这些时刻!!