Jaffer Wilson Jaffer Wilson - 5 months ago 51
Javascript Question

Facebook post extraction using Javascript sdk

I am trying to make an application that will help me in extracting the posts of the users, and even their email using the Facebook Login API. I tried the following but could not rectify where exactly from I can extract the text post and use it for my purpose of NLP experiment.

See the following code:

<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
<!-- Facebook Login Function -->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.10&appId=APP-ID";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function checkLoginState() {
FB.getLoginStatus(function(response) {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.api('/me', function(response) {

<div class="fb-login-button" data-max-rows="1" data-size="large" data-button-type="continue_with" data-show-faces="false" data-auto-logout-link="false" data-use-continue-as="true"></div>

I just want to pass the posts to a function where I can move further and make the NLP process work for it.

Here is the function that works as NLP process:


//Validation for Paste Text field
function validate()
console.log( "Inside validate");
//return false;
var obj1 = document.getElementById('for_analysis').value;
console.log("Pring value of text area")
console.log( obj1);

if(obj1.trim() == '')
console.log( "Empty space found");
alert("Please Enter some Text before submitting");
return false;
console.log( "No empty space found");
//document.getElementById("chkjq").className = "chkjq";
return true;
//paste this code under head tag or in a seperate js file.
// Wait for window load
console.log( "inside jquery");
$(window).on('load',function() {
// Animate loader off screen
console.log( "Page Loading");

//console.log( "Hello, world!");
//console.log( "Hello, world! file button");

The above function is applied to a textarea from where I am getting the text and processing it. :

<form action ="/analyze/" method="POST" name ="sendtext" id="sendtext" onsubmit="javascript:return validate()" >
{% csrf_token %}
<textarea id ="for_analysis" name ="for_analysis" form="sendtext" style="background-color: lightgrey"></textarea>
<!-- <input id="for_analysis" type="textarea" name="for_analysis" > -->
<button type="submit" class="box__button chkjq" id = "chkjq">UPLOAD</button>
<!--<button id="ana_text">Analyze</button> -->

Now I want to perform the same by extracting text post from the FB. Kindly let me know what I can do to make it right?

Answer Source

Quick example - with FB.login instead of the login button:

const getPosts = () => {
    FB.api('/me/posts', (response) => {

const getEmail = () => {
    FB.api('/me', {fields: 'name,email'}, (response) => {

FB.login((response) => {
    if (response.authResponse) {
        //user just authorized your app
}, {scope: 'email,user_posts'});

Additional info: http://www.devils-heaven.com/facebook-javascript-sdk-login/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download