Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling Javascript Function In PHP Not Working
    primarykey
    data
    text
    <p>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.</p> <p>Here is the Javascript that was written to compile the likes:</p> <pre><code>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; } </code></pre> <p>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:</p> <pre><code>&lt;script type="text/javascript"&gt; document.write(FacebookFans(40796308305)); &lt;/script&gt; </code></pre> <p>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 <code>var</code> 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 <code>var</code> fine. Anyways, any help is greatly appreciated. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload