Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Facebook integration with JavaScript 1

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
Hi,

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.

Basically I need to retrieve data from a Facebook table and present the results in a html page as a recordset, so it will probably be more than one row of results to be returned.

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


Code:
<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      : 'xxxxxxxxxxxx', 
            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: 'xxxxxxxxxx', 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
 
It could be the [tt]contains[/tt] value is incorrect. try placing wild cards in the value to search: [tt]*sam robers*[/tt], [tt]%sam robers%[/tt] or some other variation.

also, try querying for more than one user by user id, just to make sure you can retrieve multiple records back
Code:
select name, uid from user where uid=742375122 or uid=[another id you know]
this should return 2 rows and you'll know it's the FQL that contains the bug and not your code.

Jason Meckley
Senior Programmer

faq855-7190
faq732-7259
My Blog
 
Thanks Jason,

I think it is no londer the FQL that is the issue it must be the javascript. There is not much help on the internet for what i am trying to do.

Many thanks for looking.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top