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) {
statusChangeCallback(response);
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
console.log(response.authResponse.accessToken);
}
FB.api('/me', function(response) {
console.log(JSON.stringify(response));
});
});
}
</script>
<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:
<script>
//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");
//obj1.focus();
return false;
}
else{
console.log( "No empty space found");
$(".trial").show();
//document.getElementById("chkjq").className = "chkjq";
return true;
}
}
//paste this code under head tag or in a seperate js file.
// Wait for window load
$(document).ready(function(){
console.log( "inside jquery");
$(window).on('load',function() {
// Animate loader off screen
console.log( "Page Loading");
//$(".se-pre-con").fadeOut("slow");;
//$(".trial").fadeOut("slow");;
//$("#download").remove();
});
$(".chkjq").click(function(){
//console.log( "Hello, world!");
//$(".trial").show();
});
$("#filebutton").click(function(){
//console.log( "Hello, world! file button");
$(".trial").show();
});
});
</script>
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" > -->
<br/>
<button type="submit" class="box__button chkjq" id = "chkjq">UPLOAD</button>
<!--<button id="ana_text">Analyze</button> -->
<br/></form>
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?
Quick example - with FB.login
instead of the login button:
const getPosts = () => {
FB.api('/me/posts', (response) => {
console.log(response);
});
};
const getEmail = () => {
FB.api('/me', {fields: 'name,email'}, (response) => {
console.log(response);
});
};
FB.login((response) => {
if (response.authResponse) {
//user just authorized your app
getPosts();
getEmail();
}
}, {scope: 'email,user_posts'});
Additional info: http://www.devils-heaven.com/facebook-javascript-sdk-login/
Btw, you can also combine the API calls:
FB.api('/me', {fields: 'name,email,posts'}, (response) => {
console.log(response);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.