[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1520
  • Last Modified:

How to login using FB api and redirect to next page?

Hi,
I'm able to login to FB using the FB api, but to redirect to the next page (logged in page), i need to click refresh.

Is there anything that i missed out? Any help is greatly appreciated.
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>muncch</title>

      <script src="http://connect.facebook.net/en_US/all.js">
      </script>

      <script>
          function bodyload()
          { 
          FB.init({
              appId: '123455667', cookie: true,
              status: true, xfbml: true
          });

          FB.api('/me', function (user) {
              if (user.id != null) {
                  var image = document.getElementById('image');
                  image.src = 'http://graph.facebook.com/' + user.id + '/picture';
                  var name = document.getElementById('name');
                  name.innerHTML = user.name

                  var txtUserID = document.getElementById('txtUserID');
                  txtUserID.value = user.id;

                  //With user login, now redirect user to new page
                  window.location = "http://www.xxx.com/icanadd/json.aspx"
                  //alert('im logged on');
              }
              else {
                  alert('im nothing');
              }
          });

         

      }
      </script>


  </head>
 
  <body onload="bodyload();">

      <form id="form1" runat="server">

      <div id="fb-root"></div>

        <a href="https://www.facebook.com/dialog/oauth?client_id=123456&redirect_uri=http://www.xxx.com/icanadd/json.aspx">click to login</a>
        </form>

    </body>

</html>

Open in new window

0
tangteng78
Asked:
tangteng78
  • 5
  • 3
1 Solution
 
leakim971PluritechnicianCommented:
fbEnsureInit(function() {
    location.href = "http://www.xxx.com/icanadd/json.aspx";
});

Open in new window

0
 
tangteng78Author Commented:
Okay, now it's able to redirect to json.aspx, great.

 But the same issue exist on this page(json.aspx), even though i'm redirected to the page, i still need to click refresh for me to be able to access the fb logged in cookie.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
tangteng78Author Commented:
Any help is appreciated guys. Thanks.
0
 
leakim971PluritechnicianCommented:
What about :

		FB.Event.subscribe("auth.logout", function(response) {
			alert("You loggout");
		});

Open in new window


or :

		FB.Event.subscribe("auth.login", function(response) {
			t = setInterval(FB.getLoginStatus(function(response) { if(response.session && response.status != "connected") { clearInterval(t) } }), 1500);
			alert("You're logged");
		});

Open in new window

0
 
tangteng78Author Commented:
Doesn't work.

After logged in and redirect to the json.aspx page, i still need to refresh (hit F5) before i'm able to get the FB cookie so that i can extract the Graph API.

Is there an example out there that shows the whole nine yards from authentication to logged in page??

0
 
leakim971PluritechnicianCommented:
The first one take its time but it work
0
 
leakim971PluritechnicianCommented:
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now