Home FB Graph API: Grabbing all mutual friends - (#200) You do not have sufficient permissions to perform this action
Reply: 1

FB Graph API: Grabbing all mutual friends - (#200) You do not have sufficient permissions to perform this action

mding5692
1#
mding5692 Published in 2017-12-07 22:14:43Z

I am using AWS Lambda to ask for all mutual friends between current user and another user as stated here: https://developers.facebook.com/docs/graph-api/reference/user-context/all_mutual_friends/

I have looked through all the other stackoverflow answers and can't really find one close enough and have followed each of their answers to still get errors like these: Facebook Graph All Mutual Friends and "Requires a valid user is specified ..." error when using getCount

and my code looks like the below in AWS, note that I have used this node.js third-party sdk (https://github.com/node-facebook/facebook-node-sdk):

// Imports third-party fb graph api node.js sdk: https://github.com/node-facebook/facebook-node-sdk
const fbGraph = require('fb');

// Grabs app secret and app ID
const appSecret = process.env.APP_SECRET;
const appID = process.env.APP_ID;

// Uses user access token and grabs total count of all relevant mutual friends
exports.handler = (event, context, callback) => {
    // Grabs relevant details from request
    // const accessToken = event.accessToken;
    const friendUserID = event.friendUserID;

    fbGraph.api('oauth/access_token', {
        client_id: appID,
        client_secret: appSecret,
        grant_type: 'client_credentials'
    }, function (res) {
        if(!res || res.error) {
            console.log(!res ? 'error occurred' : res.error);
            return;
        }

        let access_token = res.access_token;

        // Sets options for fb graph api to work
        fbGraph.options({accessToken: access_token, appId: appID, appSecret: appSecret, timeout: 12000});

        // Sets up fields and query string for request
        const friendUserIDQueryString = '/' + friendUserID; 
        const fields = { 
            fields: 'context.fields(all_mutual_friends.limit(10))' 
        };

        // Sends api request to get all mutual friends
        fbGraph.api(friendUserIDQueryString, 'post', fields, function(response) {
            console.log(response);

            // Error handling
            if (response.error) {
                // Logs error
                context.done(null, { MutualFriendsTotalCountError: 'Error: not able to receive response' });

                // Returns error message
                return callback(new Error(`Mutual friends total count error: ${response.error}`));
            }

            // Logs successful operation
            context.done(null, { MutualFriendsTotalCountSuccess: `Success: grabbed total mutual friend count for ${friendUserID}`});

            // Returns total count of mutual friends between current and other user as integer
            return callback(null, { total_count: response.context.all_mutual_friends.summary.total_count });
        });
    });
}

but my response is now this:

{ error: 
   { message: '(#200) You do not have sufficient permissions to perform this action',
     type: 'OAuthException',
     code: 200,
     ...
}

I don't really understand it, I've used my own access token on my IOS app I'm using this for, the application app token through OAuth, and also the other user ID who exists on my app and is the one thats specific for my app and other recommended solutions to no avail.

mding5692
2#
mding5692 Reply to 2017-12-08 02:13:51Z

Ok now it works, I followed exactly with the example from this stackoverflow: Facebook Graph All Mutual Friends

I don't know whats explicitly the difference as it still looks similar to something I had before but this is what my current code looks like and works:

// Imports third-party fb graph api node.js sdk: https://github.com/node-facebook/facebook-node-sdk
const fbGraph = require('fb');

// Grabs app secret and app ID
const appSecret = process.env.APP_SECRET;
const appID = process.env.APP_ID;

// Uses user access token and grabs total count of all relevant mutual friends
exports.handler = (event, context, callback) => {
    // Grabs relevant details from request
    const accessToken = event.accessToken;
    const friendUserID = event.friendUserID;


    // Sets options for fb graph api to work
    fbGraph.options({accessToken: accessToken, appId: appID, appSecret: appSecret, timeout: 12000});

    // Sends api request to get all mutual friends
    fbGraph.api('/' + friendUserID, { fields: 'context.fields(all_mutual_friends.limit(0))'}, function(response) {

        // Error handling
        if (!response || response.error) {
            // Logs error
            console.log('MutualFriendsTotalCountError: Error: not able to receive response');

            // Returns error message
            return callback(new Error(`Mutual friends total count error: ${response.error.message}`));
        }

        // Logs successful operation
        console.log(`Success: grabbed total mutual friend count for ${friendUserID}`);

        // Returns total count of mutual friends between current and other user as integer
        return callback(null, { total_count: response.context.all_mutual_friends.summary.total_count });
    });
}

By the way, this returns the total number of app-using and non-app using mutual friends between current user and another user on AWS Lambda

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.371846 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO