Access User Information from Facebook using Nativescript {N} oAuth Plugin

Developing an Android App with NativeScript

I am in the process of creating an Android app using JavaScript and NativeScript. The initial page asks users to connect with Facebook, and my goal is to verify if an account exists with their email address.

Tools Used for Development

To handle the OAuth connection to Facebook, I am utilizing the nativescript-oauth package. My development environment is a Windows 10 machine, and I am working through the command line interface.

Code Snippets

app.js

var tnsOAuthModule = require("nativescript-oauth");

var facebookInitOptions = TnsOAuthOptionsFacebook = {
    clientId: 'REDACTED',
    clientSecret: 'REDACTED',
    scope: ['email']
};
tnsOAuthModule.initFacebook(facebookInitOptions);

application.start({ moduleName: "views/start/start" });

start.js

//...
var tnsOAuthModule = require("nativescript-oauth");
//...

exports.fbConnect = function(){
    console.log("Facebook Connect button tapped");

    tnsOAuthModule.login()
        .then(()=>{
            console.log('logged in');
            var token = tnsOAuthModule.accessToken();
            console.log("FB Auth token: " + token);
            console.log(JSON.stringify(tnsOAuthModule));
        })
        .catch((er)=>{
            console.log(er);
        });

    console.log("Login successful");
}

Facing an Issue

The above code produces the following output:

JS: Facebook Connect button tapped
...
JS: logged in
JS: FB Auth token: EAAC50oamJosBAF1F3lrGAOntENgSAZA40w4iE3rNOLP1W_REDACTED_Cb7yS9ZB1Ro4qhLroOMwZD
JS: {"instance":{"tokenResult":{"accessToken":"EAAC50oamJosBAF1F3lrGAOntENgSAZA40w4iE3rNOLP1W_REDACTED_Cb7yS9ZB1Ro4qhLroOMwZD","accessTokenExpiration":"2017-03-24T18:27:04.176Z","refreshTokenExpiration":"2017-03-24T18:27:04.176Z"},"credentials":{"authority":"https://www.facebook.com/dialog","tokenEndpointBase":"https://graph.facebook.com","authorizeEndpoint":"/oauth","tokenEndpoint":"/v2.3/oauth/access_token","clientId":"REDACTED","clientSecret":"REDACTED","redirectUri":"https://www.facebook.com/connect/login_success.html","scope":"email"}}}
JS: Application started successfully

While I can successfully obtain the access token and parse the returned object, I am struggling to retrieve the user's email address even though it is included in the specified scope.

Seeking Assistance

How can I leverage the nativescript-oauth plugin or the data from the object above to extract the user's email address as defined in the scope?

Additional Resources

Answer №1

To access more details, you need to adjust the scope settings (include "user_friends" to view their friend's list, and include "public_profile" for profile information).

var facebookInitOptions = TnsOAuthOptionsFacebook = {
    clientId: 'REDACTED',
    clientSecret: 'REDACTED',
    scope: ['email', 'user_friends', 'public_profile']
};

Ensure that in the "App review" section of your Facebook developer page, these scope fields are active and visible (indicated by a green dot next to them with data descriptions). If the provided code doesn't work, you may need to make the app live or start a submission process for approval first.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Displaying varied information based on JSON feedback using AngularJS

I am currently in the process of developing an app using AngularJS and the Ionic framework. The app will display a list of data with various subcategories for each item, depending on the account type. View sample image here The issue I am facing is that ...

Gaining entry to a JSON object within an array

I've completed various courses on JSON and put in a lot of effort to troubleshoot this bug. However, it seems that my question is too specific and I require a practical example. JSON { "date": "2017-10-15", "league": "NHL", "odds": "spreads", ...

Launching a URL in a pop-up window with customized title and address bar

I am seeking to implement a feature similar to the following: <a href="post/23">post 23</a> When a user clicks on this element, I want a popup div to fade in and load the HTML from page post/23 into it. Additionally, I would like the title an ...

If I don't utilize dependency injection in Angular, it prompts me for arguments

Attempting to implement a service like this but encountering some issues translateService = new TranslateService(); An error message pops up stating that there are 9 missing arguments. However, when I modify it to look like this constructor(private trans ...

Learn how to verify the existence of a URL or webpage using AJAX or jQuery

When a user is creating a profile, they have the option to include links to their websites or blogs that will be displayed on their profile page. Before saving these links to the database, I would like to verify if the provided URL exists. Is there a meth ...

Searching and Sorting through JSON Data in React Native

I am currently expanding my knowledge in React Native and experimenting with filtering a JSON data set on a screen. My goal is to display only the filtered results on the screen. Would it be advisable for me to create a new component called FilteredTicket? ...

"Update data on a webpage using Javascript without the need to refresh the

I encountered a problem with my code for posting messages in the "chatbox". When I include return false; at the end of the function, the data is not submitted. However, if I remove it, the data submits successfully. JavaScript Code function dopost() { ...

Express and Passport encounter a Bad Request Error message

I've created a simple express API that utilizes passport.js for authentication: const express = require("express"); const app = express(); const LocalStrategy = require("passport-local").Strategy; const passport = require("passport"); passport.use( ...

The rule "react/jsx-sort-props" does not have a valid configuration

I've been attempting to organize props names alphabetically using the eslint-plugin-react plugin but I keep encountering this error: [Error ] .eslintrc.json: Configuration for rule "react/jsx-sort-props" is invalid: Value {"callbacksLast":true,"shorth ...

Deactivate tag Script using JQuery

Is there a way to dynamically remove two <script> tags from a page at the document ready event? Each tag is assigned its own unique id. I attempted to use the following code: $("#idPrimoScript").remove(); $("#idSecondoScript").remove(); However, t ...

Display loading spinner and lock the page while a request is being processed via AJAX

Currently, I am working on a project using MVC in C#, along with Bootstrap and FontAwesome. The main objective of my project is to display a spinner and disable the page while waiting for an ajax request. Up until now, I have been able to achieve this go ...

WordPress CSS & JS files failing to enqueue properly

My attempt to integrate my CSS and JS files with WordPress has not been successful. Although my CSS works through the Custom CSS tab, this is not an ideal solution. Below is the code from my functions.php file for your reference. Can you help me troublesho ...

When using firebase.firestore(), the data displayed is completely different and does not match the content of my actual database documents

I am trying to fetch data from firebase firestore using the following code: let db = firebase.firestore(); let locations = db.collection("location"); console.log("locations", locations); However, the logged data is coming back strange and not showing the ...

How can I create a pop-out message box in HTML similar to the style used in Gmail or OkC

As someone who isn't very experienced in client development, I hope you'll forgive me for asking what might be a simple question that can easily be solved with Firebug. I'm interested in learning how to create a feature like the OKCupid or G ...

`Is there a way to effectively test an @Input component in Angular?`

Despite multiple successful attempts in the past, I am facing some difficulty getting this to function properly. Within my component, I have an input @Input data: Data, which is used in my template to conditionally display certain content. Oddly enough, du ...

Managing mouse click events in jQuery

Here on SO, I successfully implemented the mouse down handler. Now, my goal is to separate these functions into their own file named test.js. Within test.js, the code looks like this: function handleMouseDown(e) { console.log('handleMouseDown&ap ...

Encountering App Crashes during contact.save() operation with ID in Apache Cordova

I have attempted this process with various APIs and even on a physical android device, but it still crashes when trying to save. While developing an app based on contacts for android using Tools for Apache Cordova in Visual Studio and the cordova contacts ...

Safari browser removes spaces after commas in cookie values

I'm encountering an issue when trying to set a session cookie for storing an Address. It seems that whenever I include a comma followed by a space in the cookie's value, Safari automatically removes the spaces after the commas, causing the format ...

Troubleshooting the Checkbox Oncheck Functionality

Before checking out the following code snippet, I have a requirement. Whenever a specific checkbox (identified by id cfc1) is clicked, it should not show as checked. I have implemented the onCheck function for this purpose, but I'm struggling to fig ...

My goal is to prevent users from using the Backspace key within the input field

Let's say we want to prevent users from using the backspace key on an input field in this scenario. In our template, we pass the $event like so: <input (input)="onInput($event)"> Meanwhile, in our app.component.ts file, the function ...