1

我创建了一个使用 FB Javascript SDK 的简单应用程序,它在 FB 上发布我网页文本区域中给出的内容。我为此使用 fb.api,问题是它仅适用于我的用户 ID(我从中创建了应用程序)。对于其他ID,它不起作用。有人可以帮忙吗?我希望其他用户在登录后也能够在他们的墙上发帖。

<html>
<head></head>
<body>
    <div id="fb-root"></div>
    <label>Give your message here:</label><br/>
    <textarea id = "ta"></textarea><br/>
    <label>Any image?</label><br/>
    <textarea id = "pic"></textarea><br/>
    <label>Any link?</label><br/>
    <textarea id = "ta_link"></textarea><br/>
    <button onclick = "testAPI()">Click To Post!</button>
    <script>
      // Additional JS functions here
      window.fbAsyncInit = function() {
        FB.init({
          appId      : 'AppID', // App ID
          channelUrl : 'http://127.0.0.1/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) {
            if (response.status === 'connected') {
                alert("Connected");
                //testAPI();
            } else if (response.status === 'not_authorized') {
                // not_authorized
                login();
            } else {
                // not_logged_in
                login();
            }
        });
        };
         function login() {
            FB.login(function(response) {
                if (response.authResponse) {
                    //testAPI();
                } else {
                    alert("Can't connect")
                }
            });
        }
      function testAPI() {
          FB.getLoginStatus(function(response) {
            if (response.status === 'connected') {
          var tbmsg = document.getElementById("ta").value;
           var tbimg = document.getElementById("pic").value;
           var tblink = document.getElementById("ta_link").value;
          var wallPost = {};
        wallPost['message'] = tbmsg;
        if(tbmsg == "")
        {
            alert("Message box can't be empty")
        }

        if(tbimg)
        {
            wallPost['picture'] = tbimg;
        }
        if(tblink)
        {
            wallPost['link'] = tblink;
        }

        FB.api('/me/feed', 'post', wallPost , function(response) {
        if (!response || response.error) {
        alert('Error occured');
        } else {
        alert("Posted");
        }

    });
}
else
{
    alert("Login first")
}

}); }

      // Load the SDK Asynchronously
    </script>
</body>

4

0 回答 0