11import { Observable } from 'tns-core-modules/data/observable' ;
2- import { LoginEventData , logout as fbLogout } from "nativescript-facebook" ;
2+ import { LoginEventData , logout as fbLogout , getCurrentAccessToken } from "nativescript-facebook" ;
33
44let frameModule = require ( "tns-core-modules/ui/frame" ) ;
55let appSettings = require ( "tns-core-modules/application-settings" ) ;
@@ -13,22 +13,22 @@ export class HomeViewModel extends Observable {
1313
1414 constructor ( ) {
1515 super ( ) ;
16- // Get logged in user's info
17- http . getJSON ( config . FACEBOOK_GRAPH_API_URL + "/me?access_token=" + this . accessToken ) . then ( ( res ) => {
18- this . set ( "username" , res . name ) ;
19- this . set ( "userId" , res . id ) ;
20-
21- // Get logged in user's avatar
22- // ref: https://github.com/NativeScript/NativeScript/issues/2176
23- console . log ( config . FACEBOOK_GRAPH_API_URL + "/" + this . get ( "userId" ) + "/picture?type=large&redirect=false&access_token=" + this . accessToken ) ;
24- http . getJSON ( config . FACEBOOK_GRAPH_API_URL + "/" + this . get ( "userId" ) + "/picture?type=large&redirect=false&access_token=" + this . accessToken ) . then ( ( res ) => {
25- this . set ( "avatarUrl" , res . data . url ) ;
26- } , function ( err ) {
27- alert ( "Error getting user info: " + err ) ;
28- } ) ;
29- } , function ( err ) {
30- alert ( "Error getting user info: " + err ) ;
31- } ) ;
16+ // Get logged in user's info
17+ http . getJSON ( config . FACEBOOK_GRAPH_API_URL + "/me?access_token=" + this . accessToken ) . then ( ( res ) => {
18+ this . set ( "username" , res . name ) ;
19+ this . set ( "userId" , res . id ) ;
20+
21+ // Get logged in user's avatar
22+ // ref: https://github.com/NativeScript/NativeScript/issues/2176
23+ console . log ( config . FACEBOOK_GRAPH_API_URL + "/" + this . get ( "userId" ) + "/picture?type=large&redirect=false&access_token=" + this . accessToken ) ;
24+ http . getJSON ( config . FACEBOOK_GRAPH_API_URL + "/" + this . get ( "userId" ) + "/picture?type=large&redirect=false&access_token=" + this . accessToken ) . then ( ( res ) => {
25+ this . set ( "avatarUrl" , res . data . url ) ;
26+ } , function ( err ) {
27+ alert ( "Error getting user info: " + err ) ;
28+ } ) ;
29+ } , function ( err ) {
30+ alert ( "Error getting user info: " + err ) ;
31+ } ) ;
3232 }
3333
3434 private _navigate ( path : string ) {
@@ -50,4 +50,10 @@ export class HomeViewModel extends Observable {
5050 this . _navigate ( "login-page" ) ;
5151 } ) ;
5252 }
53+
54+ public getCurrentAccessToken ( ) {
55+ let accessToken = getCurrentAccessToken ( ) ;
56+
57+ alert ( "Current access token: " + JSON . stringify ( accessToken , null , '\t' ) ) ;
58+ }
5359}
0 commit comments