Thuzi / facebook-node-sdk

Modeled from the (Facebook Javascript SDK), now with the facebook-node-sdk you can now easily write the same code and share between your server (nodejs) and the client (Facebook Javascript SDK).
Other
738 stars 251 forks source link

Simple post example is failing due to invalid Access Token #125

Open Codepoet77 opened 7 years ago

Codepoet77 commented 7 years ago

This is sample code that I am using to attempt to post to a Facebook page from a node app:


var FB = require('fb');
            FB.api('oauth/access_token', {
            client_id: 'my client Id',
            client_secret: 'my secret',
            grant_type: 'client_credentials'
        }, function (res) {
            if(!res || res.error) {
                console.log(!res ? 'error occurred' : res.error);
                return;
            }            
            var accessToken = res.access_token;

            console.log(accessToken);

            //FB.setAccessToken(accessToken);

            FB.api('me/feed', 'post', { message: post.body, access_token: accessToken }, function (res2) {
                if(!res2 || res2.error) {
                  console.log(!res2 ? 'error occurred' : res2.error);
                  return;
                }
                console.log('Post Id: ' + res2.id);
              });
        });

The response to this call is:

{ message: 'An active access token must be used to query information about the current user.', type: 'OAuthException', code: 2500, fbtrace_id: 'CXQJxYMaH55' }

Can anyone suggest what I may be doing wrong here?

dantman commented 7 years ago

Please try switching to the latest version of the library: https://github.com/node-facebook/facebook-node-sdk

After that try running your code with the DEBUG=* environment variable set.

Codepoet77 commented 7 years ago

Sorry for the NOOB question but does "npm install fb" install the the version you are referring to?

This is from my package.json

"fb": "^2.0.0"
dantman commented 7 years ago

Yup, your issue is just on the wrong GitHub repo.

Try the enabling the DEBUG ENV. The newer versions have debug logs as well as request.

jrvansuita commented 7 years ago

Same Issue here.