Shrouk Khan
Shrouk Khan

Reputation: 1460

Posting to group using facebook nodejs sdk : OAuthException

I am trying to post to facebook group wall using nodejs sdk ( https://github.com/node-facebook/facebook-node-sdk )

This is a piece of code I am using :

Access token ( works fine ) :

FB.api('oauth/access_token', {
                client_id: appId,
                client_secret: appSecret,
                grant_type: 'client_credentials'
            }, function (res) {

                if (!res || res.error) {
                    var errorMessage = !res ? 'Unkown error' : res.error;
                    log.error(site + " Failed to get fb access token " + errorMessage);
                }

                var accessToken = res.access_token;
                FB.setAccessToken(accessToken);
            });

Attempt to post :

                var message = 'Hi from facebook-node-js';
                FB.api( facebookGroupId + '/feed', 'POST', {
                  //  access_token: appToken,
                    message: message
                }, function (res) {
                    if (!res || res.error) {
                        console.error(!res ? 'error occurred' : res.error);
                        return;
                    }
                    console.log('Post Id: ' + res.id);
                });

Which fails with :

{ message: '(#200) The user hasn\'t authorized the application to perform this action',
  type: 'OAuthException',
  code: 200,
  fbtrace_id: 'xxxxx' }

Now , this being a server side app, I can not pop something up to request the permission . Can someone point me where I can assign the needed permission to the app ?

Upvotes: 1

Views: 1681

Answers (2)

lars.schwarz
lars.schwarz

Reputation: 1274

You need the user to grant user_managed_groups and publish_actions permission to do so. Keep in mind that both permissions need to be reviewed by Facebook.

Upvotes: 1

Zeeshan Hassan Memon
Zeeshan Hassan Memon

Reputation: 8325

You have to have access-token to get this done, It is obvious no user would like any app to save her facebook credentials. So right approach is to first pop-up that yields access token and make use of it for posting.

Upvotes: 1

Related Questions