0

所以我一直在尝试获取一个网页来使用 Facebook OAuth 对用户进行身份验证。我一直在关注 Facebook 的关于如何做到这一点的教程,我已经完成了所有工作,但我似乎无法让它发挥作用。

这是代码...

<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function main(){ // runs all the other methods when needed, and maintains the proper path from making the form to posting to Facebook
//var imageURL = getImageURL();
//$("img[src='" + imageURL + "']").after("</br><form><input type=\"checkbox\" name=\"geo\" value=\"geolocation\"><b>Use Geolocation?</b> </br> <b>Additional Information About the Image: </b> <input type=\"comment\" name=\"cmnt\"></form>");
//alert("Form should have been placed.");
}

function testAPI() {
alert('Welcome!  Fetching your information.... ');
FB.api('/me', function(response) {
    alert('Good to see you, ' + response.name + '.');
});
}

// This function right now is hard coded to one particular image right now for testing purposes
// Should be coded in the future to return the URL of a long-pressed image
function getImageURL(){
var url = "http://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Solid_black.svg/200px-Solid_black.svg.png";
return url;
}

// Facebook login code
function login() {
FB.login(function(response) {
    if (response.authResponse) {
        // connected
        alert("Running testAPI();");
        testAPI();
    } else {
        alert("Login not complete.");
        // canceled
    }
});
}

function testAPI() {
alert('Welcome!  Fetching your information.... ');
FB.api('/me', function(response) {
    alert('Good to see you, ' + response.name + '.');
});
}
</script>
</head>
<body onload="main()">

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

  //-----------------------------
  // This is an initilization script created by Facebook. 
  //-----------------------------
  window.fbAsyncInit = function() {
alert("Running Facebook init..");
FB.init({
  appId      : '488272104524396', // App ID
  channelUrl : '//t50.novarra.net/channel.html', // Channel File
  status     : true, // check login status
  cookie     : true, // enable cookies to allow the server to access the session
  xfbml      : true  // parse XFBML
});

// Additional init code here
FB.getLoginStatus(function(response) {
    alert("Getting Login Status..");
    if (response.status === 'connected') {
        // connected
        alert("Response Status: Connected");
        $('.fblogincontainer').removeClass('hidden');
        testAPI();
    } else if (response.status === 'not_authorized') {
        alert("Response Status: Not Authorized");
        // not_authorized
        login();
    } else {
        alert("Response Status: Other");
        // not_logged_in
        login();
    }
});
  };

  // 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>

<b> Page </b>
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Solid_black.svg/200px-Solid_black.svg.png">

<div id="content">
     <div class="fblogincontainer hidden">
        <div class="fb-login-button">Login to Facebook</div>
    </div>
</div>

</body>
</html>

所以我的问题是 FB>getLoginStatus 甚至没有启动。它的警报不会弹出。此外,fb-login-button 似乎不起作用。它对我来说消失了。

4

0 回答 0