Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过API)。然后“echo$fan_count”。非常感谢你。我现在可以根据需要灵活使用风扇数量! function FacebookFans(aPageId) { if (aPageId === undefined || aPageId === n_Php_Javascript_Facebook - Fatal编程技术网

Php 通过API)。然后“echo$fan_count”。非常感谢你。我现在可以根据需要灵活使用风扇数量! function FacebookFans(aPageId) { if (aPageId === undefined || aPageId === n

Php 通过API)。然后“echo$fan_count”。非常感谢你。我现在可以根据需要灵活使用风扇数量! function FacebookFans(aPageId) { if (aPageId === undefined || aPageId === n,php,javascript,facebook,Php,Javascript,Facebook,通过API)。然后“echo$fan_count”。非常感谢你。我现在可以根据需要灵活使用风扇数量! function FacebookFans(aPageId) { if (aPageId === undefined || aPageId === null) { throw "No parameter specified. Write Facebook PageID as parameter." } if (typeof aPageId != "number")

通过API)。然后“echo$fan_count”。非常感谢你。我现在可以根据需要灵活使用风扇数量!
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;
}
<script type="text/javascript">
document.write(FacebookFans(40796308305));
</script>
 <script type="text/javascript">
 alert(FacebookFans(40796308305));
 </script>
 <script type="text/javascript">
 var a=FacebookFans(40796308305);
 document.write('a='+a);
 </script>