Facebook FQL Javascript 结果集
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用“SELECT name, pic_square, profile_url FROM user WHERE contains('sam roberts')”
似乎是字符串被切断的问题。
try using "SELECT name, pic_square, profile_url FROM user WHERE contains('sam roberts')"
seems like a string getting cut problem.