How to store email address of facebook user

0 votes
Hey,

I am using Javascript SDK for my app.

I succesfully linked facebook login with my app and stored facebook user's information like Username, First Name, Last Name, but it does not stores it email-id.

How do I do that using App42?

Thanks in advance.
asked Oct 20, 2014 in App42 Cloud API-BaaS by crazyboy24 (16 points)

1 Answer

+1 vote
 
Best answer

Hello,

Right now there is no way to add the email id in linked user call. But we have record your request in our backlog and will add this in our future release. However if you need to find the email id based on access token, you can find it easily in Get Facebook Profile method of Social service.  Please find a code snippet in above link and let us know if it helps.

Thanks,

Himanshu Sharma

 

answered Oct 21, 2014 by hs00105 (2,005 points)
selected Oct 21, 2014 by crazyboy24
I tried it,
but when I checked the console this was the error showing:

Uncaught TypeError: Cannot read property 'id' of undefined socialService.getFacebookProfile.successh.onreadystatechange


Where does the facebook profile of the user get saved? Where to check it in the App42 Dashboard?
Hello,

Could you please let us know in which SDK & version you are working on? It will helps us to resolve it on ASAP.
Thanks,
Himanshu Sharma
I am using Javascript SDK version 2.7.2
Can you share the code snippet which you are calling to get the Facebook profile of User?
Himanshu Sharma
var accessToken = "<Enter Facebook Access Token>",  
social;  
socialService.getFacebookProfile(accessToken,{  
    success: function(object) {  
    var response = JSON.parse(object);    
        social = response.app42.response.social;  
        console.log("facebookProfileId is : " + social.facebookProfile.id)  
        console.log("facebookProfileName is : " + social.facebookProfile.name)  
        console.log("facebookProfileImage is : " + social.facebookProfile.picture)  
    },  
    error: function(error) {  
    }  
});
Hello,

Kindly change the below lines of code from

        console.log("facebookProfileId is : " + social.facebookProfile.id)  
        console.log("facebookProfileName is : " + social.facebookProfile.name)  
        console.log("facebookProfileImage is : " + social.facebookProfile.picture)  
to

        console.log("facebookProfileId is : " + social.me.id)  
        console.log("facebookProfileName is : " + social.me.name)  
        console.log("facebookProfileImage is : " + social.me.picture)  
        console.log("Email Id is : " + social.me.email)  // if you have given the permission

Please make the changes and let us know if it helps.
Thanks,
Himanshu Sharma
Now in the console, this is the error:
OPTIONS https://api.shephertz.com/cloud/1.0/social/facebook/linkuser/accesscredentials?version=1.0 net::ERR_NAME_RESOLUTION_FAILED App42-all-2.7.2.min.js:1
OPTIONS https://api.shephertz.com/cloud/1.0/social/facebook/me/OAuth/CAAKIv3tLaFYBA…cMtzWZB2YSq1Tq5MwVpurJVLeE3uuDt4dL8xBJx06ZCdsXH0Ua0V4EtmNh8Cma?version=1.0 n

How can I check it in the dashboard, whether the email address came or not?
Hey.

Your solution worked. Just wanted to ask one more thing. How to see facebook user's name, email, etc in App42 Cloud API Dashboard.

Thank you very much,
Hello,

You can see Facebook user information in Facebook tab under Business Service >> Social Service. Email Field is not added their as we are in the process of adding. But you can find the other information like first name, last name, profile picture etc.
Let me know if it helps.
Thanks,
Himanshu Sharma
So if I wanted the email address, like for emailing the user's later then how can I do that? Any idea?
You can save into your app data base using No-SQL storage service, In which you can create a collection of "UserInformation" and add a JSON document which have the email ld of User. And fetch it back into the app using query interface when you want to send the email.
Please find some usefull link below and let me know if it helps.
http://api.shephertz.com/tutorial/Saving-App-Data/?index=storage-data
http://api.shephertz.com/tutorial/Querying-Your-App-Data/?index=query-appdata
http://api.shephertz.com/app42-docs/nosql-storage-service/

Thanks,
Himanshu Sharma
I am following the links, and I am almost near, just can't get that how to store already defined variables in the JSON object.
Like I saved the name and email through Get Facebook Profile method, how do I save that name and email in the JSON Object.
If i understood correctly, you can easily add your userName and emailId in Storage service by adding key value pair in jsondoc. Please find the below json doc and let me know if it helps:
"{\"userName\":\"Himanshu Sharma\",\"emailId\":\"himanshu.sharma@shephertz.co.in\"}"

Thanks
No, here you have to define the userName and emaiid, but I have already stored it in a variable named userName and email.
Not an issue you can create as an email in JSON Document. Could you please elaborate your last query so that i can provide a better support to you?
Thanks,
Himanshu Sharma
var social;
              var accessToken =  UseraccessToken;

        socialService.getFacebookProfile(accessToken,{  
            success: function(object) {  
            var response = JSON.parse(object);    
                social = response.app42.response.social;  
                console.log("facebookProfileId is : " + social.me.id)  
                console.log("facebookProfileName is : " + social.me.name)  
                console.log("facebookProfileImage is : " + social.me.picture)  
                console.log("Email Id is : " + social.me.email);
                email = social.me.email;
                name = social.me.name;
              },  
            error: function(error) {  
            }  
        });  


In the above snippet I saved user's name and email.

Now I want to save these values in json, so that I can contact them later and identify them with their email and name, as I can't see user's email-id in Business Service > Social.
Hello ,

Kindly replace your above code snippet with below code and change the data base name and collection and run:
var social;
var accessToken =  UseraccessToken,
dbName = "<Your_DataBase_Name>",
collectionName = "<Your_Collection_Name>";
var json = new Object();
var storage ;  
var storageService = App42Storage();
socialService.getFacebookProfile(accessToken,{  
    success: function(object) {  
    var response = JSON.parse(object);    
        social = response.app42.response.social;  
        email = social.me.email;
        name = social.me.name;
       
        json.name = name;
        json.email =email;
        storageService.insertJSONDocument(dbName, collectionName, json,{  
            success: function(object)
            {  
                var response = JSON.parse(object);  
                response = response.app42.response.storage;
                console.log("dbName is " + storage.dbName)
                console.log("objectId is " + storage.jsonDoc._id.$oid)
                console.log("Created At is "+storage.jsonDoc._$createdAt)
                console.log("Updated At is "+storage.jsonDoc._$updatedAt)
            },  
            error: function(error) {  
            }  
        });
    },  
    error: function(error) {  
    }  
});  

Let me know if it helps.
Thanks,
Himanshu Sharma
In the above snippet you combined Get Facebook Profile and saving JSON Object, can you please separate them, because I am first collecting facebook profile and if certain condition is true then save the name and email in the JSON Object. And it will be easier to understand.

Thanks.
Abdul.
Oops! Sorry, you din't combined the two methods, this is only for JSON object, realized it later. Sorry for the late reply.

Thanks.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...