Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Codepoet77 opened this issue Oct 15, 2017 · 4 comments
Open

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

Codepoet77 opened this issue Oct 15, 2017 · 4 comments

Comments

@Codepoet77
Copy link

Codepoet77 commented Oct 15, 2017

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
Copy link

dantman commented Oct 15, 2017

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
Copy link
Author

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
Copy link

dantman commented Oct 15, 2017

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
Copy link

Same Issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants