Get Facebook token after login, Angular


#1

Hi all,

is there any way to retrieve the facebook acces token after login with Firebase and Angular?

By default after login the response returns some data about the user, but if i need to get other information i think it’s necesary to use the API Graph with the acces token, is not?


#2

Are you using a plugin to interact with Facebook? If not, I’d recommend the oAuth plugin: https://www.npmjs.com/package/nativescript-oauth by Alex Ziskind to help you manage these sort of authentications.


#3

i Tested it, but when i integrated firebase i removed it because i login with Firebase.

is there any way to login with firebase and use nativescript-oauth to make calls to the facebook api??

For that i think that should retrieve the acces token of Facebook from firebase auth and use it on nativescript-oauth… but that is my problem i don’t know how to retrieve it…

Thanks for the answer jen!


#4

The firebase plugin supports social logins including Facebook: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/AUTHENTICATION.md

Does that answer your question?


#5

(Sorry, I didn’t read properly - you are using Firebase, so that plugin will help you with social logins)


#6

Thanks for the answer jen!

Actually i’m able to do the login with facebook, that’s not my problem, my problem is make calls to the facebook api…

Exists any way with firebase to make api calls for example to retrieve the user friends??


#7

ahhh! I finally understand what you’re trying to do, a sort of firebase + Facebook combo. Well, I think you’ll want some kind of custom integration. We don’t have a full Facebook plugin, I believe, just the ability to login etc. It’s a big buildout. Can you, however, simply make calls to the Facebook API via plain REST / http calls? I haven’t worked with that API for ages.

Anyone else here doing extensive work with Facebook?


#8

Yes i think that i can make api calls via REST against Facebook API Graph but for that i need the facebook access token that firebase generates.

And that is my initial problem :((

Thanks again Jen!

Anyone else who knows about this?


#9

@adangnzlz

Basically you take that token, attach it to further rest calls to facebook graph API for whatever data you need. The facebook graph api also requires you to add the scope elements you want to be authorized to access by the user:

var facebookInitOptions: tnsOAuthModule.ITnsOAuthOptionsFacebook = {
    clientId: '**************',
    clientSecret: '********************',
    scope: ['email', 'public_profile'],
};

The example given by the nativescript oauth team just includes email but you add public_profile or friends list as well.

I’ll see if I can combine the API call for data into one but my understanding is that facebook requires seperate calls for more data. The call that nativescript-oauth does just retrieves the token for access.