0

why does the following javascript return empty data?

        FB.getLoginStatus(function(response) {
                      if (response.status === 'connected') {
                          var accessToken = response.authResponse.accessToken;
                            console.log("accessToken:", accessToken);
                          //mainCall(accessToken);

            FB.api('/me/events/',
                  'GET',
                    {
                        "pretty":"1",
                        "limit":100,
                        "access_token": accessToken
                    },
                      function(response) {
                      newVue(response); // small vue.js template 
                      console.log(response);
                        });
                    } 
            } );

if I separately get the access token, hardcode it then call FB.api I get an array of 100 results as expected.

fitsum
  • 1
  • 6
  • 1
    There is no need to specify the access token yourself (unless you wanted to use a different one than a user access token for the current app user), the SDK handles that on its own. – CBroe Jul 26 '17 at 07:35
  • Sending access_token with the request returns OAuthException error with message "An active access token must be used to query information about the current user." I know I need the access_token. as I said above if I hardcode it into the req I have no problem. it's only when I try to capture it then pass it to FB.api's params that I get empty array – fitsum Jul 27 '17 at 00:25
  • There should be no need to explicitly pass that parameter in the first place. Can you show how you are initializing the SDK? – CBroe Jul 27 '17 at 07:54
  • `window.fbAsyncInit = function() { FB.init({ appId : '###############', xfbml : true, version : 'v2.10' }); FB.AppEvents.logPageView(); ` – fitsum Aug 03 '17 at 17:42
  • Add `status: true`, and see what happens then. – CBroe Aug 03 '17 at 17:50
  • Thanks for the advice @CBroe, your suggestion made no difference. however I was able to fix by doing `FB.api('/me/events/?access_token=' + FB.getAccessToken(),` – fitsum Aug 04 '17 at 00:28
  • this question can be closed – fitsum Aug 04 '17 at 00:29

0 Answers0