Hi,
Each time a user logs in successfully to my app I want to call a function that gets the user’s friends list from facebook and then inserts it to the user collection.
on the client i call an on login function:
Accounts.onLogin(function(){
const userId = Meteor.userId();
const user = Meteor.users.findOne(userId);
const fId = user.services.facebook.accessToken;
Meteor.call('getFriendsData', fId);
console.log('getFriendsData - onLogin');
});
On the server I have a method that runs the http method:
Meteor.methods({
getFriendsData: function(fbAccessToken) {
var data = HTTP.call("GET", 'https://graph.facebook.com/me/friends', { params: { access_token: fbAccessToken } },(error, results) => {
resName = results.data.data;
Meteor.users.insert( { _id: this.userId }, {friends: resName} );
});
}
});
The friends list returns correctly ( if i console.log() ) it i see the data, but when i try to insert it to the collection i get the following eror:
“Exception in callback of async function: TypeError: callback is not a function”
Is my problem the facte that i try to insert if from the call back? is it my insert and how i wrote it?
Other suggestions how can i insert the data to the collection?
FYI, the data returns as an array of objects…
Many thanks!