【问题标题】:Facebook OAuth programming, trying to get a user to authenticateFacebook OAuth 编程,试图让用户进行身份验证
【发布时间】:2012-10-07 01:36:03
【问题描述】:

我正在尝试做这个教程https://developers.facebook.com/docs/howtos/login/getting-started/

我已经完成了本教程提供的所有必要(我认为)。它的目标是让您的网页使用 OAuth 验证用户的 Facebook 信息。

我的HTML代码如下...

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.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 getImageURL(){
    var url = "http://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Solid_black.svg/200px-Solid_black.svg.png";
    return url;
}

function login() {
    FB.login(function(response) {
        if (response.authResponse) {
            // connected
            testAPI();
        } else {
            // cancelled
        }
    });
}

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. 
  //-----------------------------
  // Additional JS functions here
  window.fbAsyncInit = function() {
FB.init({
  appId      : 'hiddenappid', // App ID
  channelUrl : 'hiddenwebpage', // 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) {
        if (response.status === 'connected') {
            // connected
        } else if (response.status === 'not_authorized') {
            // not_authorized
            login();
        } else {
            // 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">

</body>
</html>

这是一些代码,但主要是教程中的所有代码。你基本上可以忽略其余的。

我只是想知道如何让这个身份验证脚本运行?当我启动页面时,什么也没有发生。

另外,我不是从实际网页运行它,我只是运行 html 文件。如果这可能会影响它,我也支持代理。提前致谢!

【问题讨论】:

    标签: javascript facebook oauth


    【解决方案1】:

    该页面必须可公开访问,并且您在 Facebook 应用中定义的 URL 必须与正在访问的 url 匹配。前几天我的测试站点http://omgtrolls.com

    也遇到了同样的设置

    【讨论】:

    • 我还有什么需要做的吗?喜欢它应该自动运行吗?
    • 哦,好吧,我现在正在查看源代码,我知道你是如何做到的。
    • 希望你能从中解析出正确的东西。它只是我的测试域,我正在玩一些想法,所以有点混乱。
    猜你喜欢
    • 2011-09-09
    • 2011-11-27
    • 2014-07-09
    • 2011-09-17
    • 2019-11-09
    • 1970-01-01
    • 2015-08-30
    • 1970-01-01
    • 2013-02-04
    相关资源
    最近更新 更多