Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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
Javascript 在用户登录Facebook时显示授权对话框_Javascript_Asp.net_Facebook - Fatal编程技术网

Javascript 在用户登录Facebook时显示授权对话框

Javascript 在用户登录Facebook时显示授权对话框,javascript,asp.net,facebook,Javascript,Asp.net,Facebook,当我从我的应用程序中使用以下链接以防用户未登录Facebook时,Facebook登录显示,然后用户验证应用程序,然后应用程序显示 <a href="https://www.facebook.com/dialog/oauth?client_id=521577774587246&redirect_uri=http://localhost:55549/fb/&scope=email,read_stream">Facebook</a> 如果用户已登录并从F

当我从我的应用程序中使用以下链接以防用户未登录Facebook时,Facebook登录显示,然后用户验证应用程序,然后应用程序显示

<a href="https://www.facebook.com/dialog/oauth?client_id=521577774587246&redirect_uri=http://localhost:55549/fb/&scope=email,read_stream">Facebook</a>

如果用户已登录并从Facebook搜索框中搜索应用程序,则会显示带有Facebook登录按钮的default.aspx

如何向用户显示授权对话框而不是登录按钮

以下是default.aspx javascript-

<script type="text/javascript">
        window.fbAsyncInit = function () {
            FB.init({
                appId: '521577774587246', // App ID
                status: true, // check login status
                cookie: true, // enable cookies to allow the server to access the session
                xfbml: true  // parse XFBML
            });

            // Additional initialization code here

            FB.Event.subscribe('auth.authResponseChange', function (response) {
                if (response.status === 'connected') {
                    // the user is logged in and has authenticated your
                    // app, and response.authResponse supplies
                    // the user's ID, a valid access token, a signed
                    // request, and the time the access token 
                    // and signed request each expire
                    var uid = response.authResponse.userID;
                    var accessToken = response.authResponse.accessToken;

                    // TODO: Handle the access token

                    // Do a post to the server to finish the logon
                    // This is a form post since we don't want to use AJAX
                    var form = document.createElement("form");
                    form.setAttribute("method", 'post');
                    form.setAttribute("action", 'loadMainPage.ashx');

                    var field = document.createElement("input");
                    field.setAttribute("type", "hidden");
                    field.setAttribute("name", 'accessToken');
                    field.setAttribute("value", accessToken);
                    form.appendChild(field);
                    //                    alert(accessToken);
                    document.body.appendChild(form);
                    form.submit();

                } else if (response.status === 'not_authorized') {
                    // the user is logged in to Facebook, 
                    // but has not authenticated your app

                    window.top.location = "https://www.facebook.com/dialog/oauth?client_id=521599834587246&redirect_uri=http://localhost:55549/fb/&scope=email,read_stream";
                } else {
                    // the user isn't logged in to Facebook.

                }
            });

        };

        // Load the SDK Asynchronously
        (function (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.js";
            ref.parentNode.insertBefore(js, ref);
        } (document));
    </script>

window.fbAsyninit=函数(){
FB.init({
appId:'52157774587246',//应用ID
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
//这里有额外的初始化代码
FB.Event.subscribe('auth.authResponseChange',函数(响应){
如果(response.status===“已连接”){
//用户已登录并已验证您的身份
//app和response.authResponse提供
//用户ID、有效访问令牌、签名
//请求,以及访问令牌的时间
//和签名的请求都将过期
var uid=response.authResponse.userID;
var accessToken=response.authResponse.accessToken;
//TODO:处理访问令牌
//向服务器发送帖子以完成登录
//这是一个表单帖子,因为我们不想使用AJAX
var form=document.createElement(“表单”);
form.setAttribute(“方法”,“post”);
setAttribute(“action”,“loadMainPage.ashx”);
var字段=document.createElement(“输入”);
field.setAttribute(“类型”、“隐藏”);
field.setAttribute(“名称”,“accessToken”);
field.setAttribute(“值”,accessToken);
表单。追加子项(字段);
//警报(accessToken);
文件.正文.附件(表格);
表单提交();
}else if(response.status===“未授权”){
//用户已登录到Facebook,
//但尚未验证您的应用程序
window.top.location=”https://www.facebook.com/dialog/oauth?client_id=521599834587246&redirect_uri=http://localhost:55549/fb/&scope=email,读“流”;
}否则{
//用户未登录到Facebook。
}
});
};
//异步加载SDK
(职能(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.js”;
ref.parentNode.insertBefore(js,ref);
}(文件);
如中所述,我使用FB.login代替FB.Event.subscribe('auth.authResponseChange',现在它请求授权