0

I'm trying to build a little google apps script to get some data from the Facebook Insight API. It's a total unfamiliar ground for me so I'm trying to build this step by step.

Until now I've only wrote the following script, I know it doesn't return anything but at last it should work so I can start asking for data :

function myFuntion() {  

window.fbAsyncInit = function() {
    FB.init({
      appId      : 'My_appid',
      xfbml      : true,
      version    : 'v2.1'
    });
  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "https://connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));

}

when I'm running this, I've the following error "window" is not defined.. What does it mean ? what do I have this error ?

thanks !

Simon Breton
  • 2,638
  • 7
  • 50
  • 105

1 Answers1

1

Possible duplicate

window is a reference to the browser window: This code snippet is intended more for use in a browser than in an Apps Script sample.

To make use of the API within Apps Script, you'll want to use UrlFetchApp to make requests.

The Facebook documentation shows examples for Curl which could be translated to the UrlFetchApp requests you need to make.

You'll need to generate an access token, which you'll need to include with the requests.

Community
  • 1
  • 1
Bardy
  • 2,100
  • 1
  • 13
  • 11
  • I've been reading multiple time the question you've mentioned but couldn't really understand.But your answer is really clear thank a lot. – Simon Breton Nov 18 '16 at 21:56