When using Meteor, with the new authentication system, how can I get facebook access token, when logged with accounts-facebook
package?
get it either from a Meteor.method:
// server
Meteor.methods({
getAccessToken : function() {
try {
return Meteor.user().services.facebook.accessToken;
} catch(e) {
return null;
}
}
});
// client
Meteor.call("getAccessToken", function(error, accessToken){
console.log(accessToken);
})
or publish it:
//server
Meteor.publish("currentUserAccessToken", function(){
var self = this;
if (this.userId()){
handle = Meteor.users.find(this.userId()).observe({
added: function(user){
self.set("currentUserAccessToken", user._id, {value: user.services.facebook.accessToken});
self.flush();
},
changed: function(user){
self.set("currentUserAccessToken", user._id, {value: user.services.facebook.accessToken});
self.flush();
}
});
this.onStop(function() {
handle.stop();
});
}
});
//client
var AccessToken = new Meteor.Collection("currentUserAccessToken");
Meteor.subscribe("currentUserAccessToken");
//access the value
var accessToken = AccessToken.findOne().value;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With