I'm new to Google Documents and have set up a spreadsheet that accesses the amount of "Likes" on three different Facebook pages. The code is part of the library on Google Documents but I'm trying to take the resulting total and pull it up on my site which is PHP. I'm starting simply with one site just because I can't get it working.
Here is the Javascript that was written to compile the likes:
function FacebookFans(aPageId)
{
if (aPageId === undefined || aPageId === null)
{
throw "No parameter specified. Write Facebook PageID as parameter."
}
if (typeof aPageId != "number")
throw "Parameter must be number.";
// See http://developers.facebook.com/docs/reference/fql/page/ for API documentation
var url = "http://api.facebook.com/method/fql.query?query=SELECT%20page_id,page_url,fan_count%20FROM%20page%20%20WHERE%20page_id=%22" + encodeURIComponent(aPageId) + "%22";
var response = UrlFetchApp.fetch(url);
if (response.getResponseCode() != 200)
throw "Unexpected response code from Facebook.";
var responseText = response.getContentText();
if (responseText == null || responseText == "")
throw "Empty response from Facebook.";
var fan_count = 0;
try
{
var xml = Xml.parse(responseText, false);
var page = xml.getElement().getElement();
if (page == null)
throw "Wrong PageID.";
fan_count = parseInt(page.getElement("fan_count").getText());
}
catch (e)
{
throw "Problem with response from Facebook: " + e;
}
return fan_count;
}
Now, to preface, I am very new at Javascript so don't kill me if my code is way off, I'm still trying to understand. I tried to run this in the body:
<script type="text/javascript">
document.write(FacebookFans(40796308305));
</script>
I figured the function returns a value and this would print that value out (the number btw is Coca Cola's Facebook page ID, figured it was a good one to test with). Is this a conflict between Javascript and PHP? I know that's a mixture of client-side and server side scripts. The reason I'm not sure what's wrong though is that I set a var inside the Javascript and then used to document.write to call it back just to test that my code was valid and it recalled the var fine. Anyways, any help is greatly appreciated. Thanks.

document.writeyou get nothing on your page? Try using firebug for firefox to see if javascript throws any error - if it does, post it.console.log('some simple text')insideFacebookFansfunction and check the result in firebug. maybe it will help us somehow.