How to let Facebook Login button redirect to a particular URL

后端 未结 2 1013
借酒劲吻你
借酒劲吻你 2020-12-04 19:52

This is the info on Facebook Login button

http://developers.facebook.com/docs/guides/web/

So it will render a Login button, and a user can click on it to log

2条回答
  •  無奈伤痛
    2020-12-04 20:07

    FBML option: This should give you the functionality you want (with xfbml:true in FB.init):

    
    
    

    When the user is logged in, it changes to "Log Out." Also, if the user has not granted permissions to the app, it pops-up the request permission dialog.

    Custom option: If you don't like using FBML, you can make your own Facebook login button like this:

    HTML:

    
    

    Javascript:

    FB.init({appId: 'YourAPPID', status: true, cookie: true, xfbml: true, oauth : true});
    FB.getLoginStatus(function(response) {
        if (response.status.toString().indexOf("connected")>-1) {
            initAll(); //User is connected and granted permissions
            FB.api("/me", function (response) {
                document.getElementbyId("THE_BUTTON").value = 
                                                "Logged in as " + response.name;
            });
        } else { 
            // This URL is specially formed to ask permissions for your app. You change the 
            // permissions and your appID
            //redirect_uri = Change this to your desired callback URL
            top.location=window.location="http://www.facebook.com/dialog/oauth/?scope=read_stream,publish_stream,friends_photos,friends_activities&client_id="yourAPPID(nobrackets)"&redirect_uri=http://apps.facebook.com/filtered_feed/&response_type=code";
        }
    });
    

    So if the user is logged in, the button will be replaced with "Logged in as user's name." Otherwise, the OAuth Dialog will appear.

提交回复
热议问题