javascript - 如何仅注销我的应用程序而不注销我的 Facebook 帐户?

标签 javascript facebook facebook-graph-api

我在我的网络应用程序上使用 facebook javascript sdk。

我正在使用图形 API 登录我的应用程序

当我退出我的应用程序时,

我的应用程序注销了,我的 facebook 帐户也注销了。

如何只注销我的应用程序而不注销我的 Facebook 帐户?

如果有人找到解决方案,请帮助我。

这是我的代码-

<script type="text/javascript">     

        var button;
        var userInfo;

        window.fbAsyncInit = function() {
            FB.init({ appId: '########', 
                status: true, 
                cookie: true,
                xfbml: true,
                oauth: true});

           showLoader(true);

           function updateButton(response) {
                button       =   document.getElementById('fb-auth');
                userInfo     =   document.getElementById('user-info');
                userdata =   document.getElementById('user-data');
                if (response.authResponse) {
                    //user is already logged in and connected
                    FB.api('/me', function(info) {
                        login(response, info);
                    });

                    button.onclick = function() {
                        FB.logout(function(response) {
                            logout(response);
                        });
                    };
                } else {
                    //user is not connected to your app or logged out
                    button.innerHTML = 'Login';
                    button.onclick = function() {
                        showLoader(true);
                        FB.login(function(response) {
                            if (response.authResponse) {
                                FB.api('/me', function(info) {
                                    login(response, info);
                                });    
                            } else {
                                //user cancelled login or did not grant authorization
                                showLoader(false);
                            }
                        },                                 {scope:'email,user_birthday,status_update,publish_stream,user_about_me'});   
                    }
                }
            }

            // run once with current status and whenever the status changes
            FB.getLoginStatus(updateButton);
            FB.Event.subscribe('auth.statusChange', updateButton);  
        };
        (function() {
            var e = document.createElement('script'); e.async = true;
            e.src = document.location.protocol 
                + '//connect.facebook.net/en_US/all.js';
            document.getElementById('fb-root').appendChild(e);
        }());


        function login(response, info){
            if (response.authResponse) {
                var accessToken                                 =   response.authResponse.accessToken;

                userInfo.innerHTML                             = '<img src="https://graph.facebook.com/' + info.id + '/picture">' + info.name
                                                                 + "<br /> Your Access Token: " + accessToken;


        button.innerHTML                               = 'Logout';
                showLoader(false);
                document.getElementById('other').style.display = "block";

            }
        }

        function logout(response){
            userInfo.innerHTML                             =   "";
            document.getElementById('debug').innerHTML     =   "";
            document.getElementById('other').style.display =   "none";
            showLoader(false);
        }

        //stream publish method
        function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){
            showLoader(true);
            FB.ui(
            {
                method: 'stream.publish',
                message: '',
                attachment: {
                    name: name,
                    caption: '',
                    description: (description),
                    href: hrefLink
                },
                action_links: [
                    { text: hrefTitle, href: hrefLink }
                ],
                user_prompt_message: userPrompt
            },
            function(response) {
                showLoader(false);
            });

        }
        function showStream(){
            FB.api('/me', function(response) {
                //console.log(response.id);
                streamPublish();
            });
        }           

  function share(){
            showLoader(true);
            var share = {
                method: 'stream.share',
                u: 'http://www.appovative.com/'
            };

            FB.ui(share, function(response) { 
                showLoader(false);
                console.log(response); 
            });
        }



        function setStatus(){
            showLoader(true);

            status1 = document.getElementById('status').value;
            FB.api(
              {
                method: 'status.set',
                status: status1
              },
              function(response) {
                if (response == 0){
                    alert('Your facebook status not updated. Give Status Update   Permission.');
                }
                else{
                    alert('Your facebook status updated');
                }
                showLoader(false);
              }
            );
        }

        function showLoader(status){
            if (status)
                document.getElementById('loader').style.display = 'block';
            else
                document.getElementById('loader').style.display = 'none';
        }

    </script>

最佳答案

Facebook 使用 Oauth2。 注销您的应用程序的方法只是让您当前的授权 token 过期。 在数据中解释:

How can I force a facebook access token to expire?

关于javascript - 如何仅注销我的应用程序而不注销我的 Facebook 帐户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21847605/

相关文章:

javascript - Rxjs - switchMap 到 http 将可观察到的字符从热变为冷

javascript - fbevents.js 可以覆盖 Google Analytics 事件跟踪吗?

Facebook 隐私政策错误

android - 如何从 Android 应用程序在应用程序的 Facebook 墙上发布提要?

javascript - JQuery 变量声明

javascript - HTML读取用户未选择的本地文件

javascript - 从 facebook insted of facebook 浏览器在默认浏览器中打开我的网站

android - 已弃用的 REST API - android

c++ - 是否可以创建一个单例 C++ 以使用对 Facebook API 的 HTTP 请求进行身份验证和发布?

javascript - 如何让移动浏览器保持唤醒状态