[英]Facebook post extraction using Javascript sdk
我正在嘗試制作一個應用程序,它可以幫助我使用 Facebook 登錄 API 提取用戶的帖子,甚至是他們的電子郵件。 我嘗試了以下但無法糾正我可以從哪里提取文本帖子並將其用於我的 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>
我只是想將帖子傳遞給一個函數,在那里我可以進一步移動並使 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 中提取文本帖子來執行相同的操作。 請讓我知道我能做些什么來使它正確?
快速示例 - 使用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);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.