Facebook FQL Javascript 结果集

发布于 2024-12-17 22:22:00 字数 2192 浏览 0 评论 0原文

我对 Facebook 集成非常陌生,遇到了困难,希望有人能帮助我。我已经阅读了很多文章并测试了各种代码示例来实现我所需要的,我认为我能得到的最接近的是 FQL 和 JavaScript。我详细介绍了我将要使用它的用途,但基本上我需要从 Facebook 表中检索数据并将结果呈现在 html 页面中。

当某物 = 某物时查询单个项目时,我可以进行此操作,单个结果将打印到我的 html 页面中的屏幕上,但是当我更改查询以使其返回多个结果时,代码似乎失败而没有任何错误。

这是一个示例查询,我试图在下面的示例 javascript 代码中工作,但它返回一个 javascript 错误。我知道查询很好,因为可以在这里进行测试。

FQL SQL 查询的测试页 https://developers.facebook.com/docs/reference/rest/fql。查询/

示例查询 SELECT name, pic_square, profile_url FROM user WHERE contains('sam roberts')

上述查询替换下面工作示例中的查询时出错。

SCRIPT1006:预期为 ')' facebook_2.html,第 29 行字符 95

这是我的工作示例,仅检索一行数据,您可以运行它,但它需要位于网络服务器上。如果您有任何建议,请告诉我,我真的需要它使用 JavaScript 工作,因为这是我使用过的唯一语言。

<html>
    <head>
      <title>My Facebook Login Page</title>
    </head>
    <body>
    <div id="msg"></div>
      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          FB.init({
            appId      : '2xxxxxx',
            status     : true, 
            cookie     : true,
            xfbml      : true
          });
        };
        (function(d){
           var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
           js = d.createElement('script'); js.id = id; js.async = true;
           js.src = "//connect.facebook.net/en_US/all.js";
           d.getElementsByTagName('head')[0].appendChild(js);
         }(document));
      </script>

      <script>
        function doSomething()
        {
            FB.init({appId: '2xxxxxxxx', status: true, cookie: true, xfbml: true});
            var query = FB.Data.query('select name, uid from user where uid=742375122');
            query.wait(function(rows)
            {
             document.getElementById('msg').innerHTML = 'name is ' + rows[0].name;
            });

        }


      </script>



      <input type="button" value="Click here" onClick="doSomething()">
    </body>
 </html>

感谢您的关注。

I am very new to Facebook integration and have hit a wall which I hope someone can help me with. I have read through many articles and tested various code samples to achieve what I need and I think the nearest I can get is FQL and JavaScript. I go into exactly what I am going to use it for but basically I need to retrieve data from a Facebook table and present the results in a html page.

I have this working when querying a single item when something is = to something, the single result is printed to screen in my html page but when I alter the query so that it returns more than one result the code seems to be failing without any errors.

Here is an example query I am trying to get working in the sample javascript code below but it returns a javascript error. I know the query is good because it can be tested here.

Test page for FQL SQL queries
https://developers.facebook.com/docs/reference/rest/fql.query/

example query
SELECT name, pic_square, profile_url FROM user WHERE contains('sam roberts')

Error when above query repalces query in working example below.

SCRIPT1006: Expected ')'
facebook_2.html, line 29 character 95

Here is my working example that retrieves just a single row of data, you can run this but it needs to be on a web server.If you have any advice please let me know, I really need it to work in JavaScript as this is the only language I have experience in.

<html>
    <head>
      <title>My Facebook Login Page</title>
    </head>
    <body>
    <div id="msg"></div>
      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          FB.init({
            appId      : '2xxxxxx',
            status     : true, 
            cookie     : true,
            xfbml      : true
          });
        };
        (function(d){
           var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
           js = d.createElement('script'); js.id = id; js.async = true;
           js.src = "//connect.facebook.net/en_US/all.js";
           d.getElementsByTagName('head')[0].appendChild(js);
         }(document));
      </script>

      <script>
        function doSomething()
        {
            FB.init({appId: '2xxxxxxxx', status: true, cookie: true, xfbml: true});
            var query = FB.Data.query('select name, uid from user where uid=742375122');
            query.wait(function(rows)
            {
             document.getElementById('msg').innerHTML = 'name is ' + rows[0].name;
            });

        }


      </script>



      <input type="button" value="Click here" onClick="doSomething()">
    </body>
 </html>

Thanks for looking.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝不服输 2024-12-24 22:22:00

尝试使用“SELECT name, pic_square, profile_url FROM user WHERE contains('sam roberts')”
似乎是字符串被切断的问题。

<html>
    <head>
      <title>My Facebook Login Page</title>
    </head>
    <body>
    <div id="msg"></div>
      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          FB.init({
            appId      : '283998891634567',
            status     : true, 
            cookie     : true,
            xfbml      : true
          });
        };
        (function(d){
           var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
           js = d.createElement('script'); js.id = id; js.async = true;
           js.src = "//connect.facebook.net/en_US/all.js";
           d.getElementsByTagName('head')[0].appendChild(js);
         }(document));
      </script>

      <script>
        function doSomething()
        {
            FB.init({appId: '283998891634567', status: true, cookie: true, xfbml: true});
            var query = FB.Data.query("SELECT name, pic_square, profile_url FROM user WHERE contains('sam roberts')");
            query.wait(function(rows)
            {
             document.getElementById('msg').innerHTML = 'name is ' + rows[0].name;
            });

        }


      </script>



      <input type="button" value="Click here" onClick="doSomething()">
    </body>
 </html>

try using "SELECT name, pic_square, profile_url FROM user WHERE contains('sam roberts')"
seems like a string getting cut problem.

<html>
    <head>
      <title>My Facebook Login Page</title>
    </head>
    <body>
    <div id="msg"></div>
      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          FB.init({
            appId      : '283998891634567',
            status     : true, 
            cookie     : true,
            xfbml      : true
          });
        };
        (function(d){
           var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
           js = d.createElement('script'); js.id = id; js.async = true;
           js.src = "//connect.facebook.net/en_US/all.js";
           d.getElementsByTagName('head')[0].appendChild(js);
         }(document));
      </script>

      <script>
        function doSomething()
        {
            FB.init({appId: '283998891634567', status: true, cookie: true, xfbml: true});
            var query = FB.Data.query("SELECT name, pic_square, profile_url FROM user WHERE contains('sam roberts')");
            query.wait(function(rows)
            {
             document.getElementById('msg').innerHTML = 'name is ' + rows[0].name;
            });

        }


      </script>



      <input type="button" value="Click here" onClick="doSomething()">
    </body>
 </html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文