Facebook post 使用 Javascript sdk 提取
Facebook post extraction using Javascript sdk
我正在尝试开发一个应用程序来帮助我提取用户的 post,甚至是他们使用 Facebook 登录 API 的电子邮件。我尝试了以下但无法纠正我可以提取文本 post 并将其用于我的 NLP 实验目的的确切位置。
见以下代码:
<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>
我只是想将 post 传递给一个函数,我可以在其中进一步移动并使 NLP 过程为其工作。
这是作为 NLP 过程的函数:
<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>
上述函数应用于我从中获取文本并对其进行处理的文本区域。 :
<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>
现在我想通过从 FB 中提取文本 post 来执行相同的操作。请让我知道我能做些什么来使它正确?
快速示例 - 使用 FB.login
而不是登录按钮:
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'});
附加信息:http://www.devils-heaven.com/facebook-javascript-sdk-login/
顺便说一句,您还可以组合 API 个调用:
FB.api('/me', {fields: 'name,email,posts'}, (response) => {
console.log(response);
});
我正在尝试开发一个应用程序来帮助我提取用户的 post,甚至是他们使用 Facebook 登录 API 的电子邮件。我尝试了以下但无法纠正我可以提取文本 post 并将其用于我的 NLP 实验目的的确切位置。
见以下代码:
<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>
我只是想将 post 传递给一个函数,我可以在其中进一步移动并使 NLP 过程为其工作。
这是作为 NLP 过程的函数:
<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>
上述函数应用于我从中获取文本并对其进行处理的文本区域。 :
<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>
现在我想通过从 FB 中提取文本 post 来执行相同的操作。请让我知道我能做些什么来使它正确?
快速示例 - 使用 FB.login
而不是登录按钮:
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'});
附加信息:http://www.devils-heaven.com/facebook-javascript-sdk-login/
顺便说一句,您还可以组合 API 个调用:
FB.api('/me', {fields: 'name,email,posts'}, (response) => {
console.log(response);
});