Using javascript sdk to call facebook api
I am trying to use the Facebook API Javascript SDK to check if a Facebook page (not a profile, just a place page) exists or not. I am using two separate files, one HTML with a simple form in it and a script that calls the facebook api. However, the FB.api method doesn't seem to return anything. I don't have much experience with api, so I would appreciate any help.
Html file code:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="style_admin.css" />
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
<script type="text/javascript" src="url_ver.js"></script>
</head>
<body>
<form action="" method="post" onsubmit="verifyUrl()">
URL: <input id="url" type="text" name="page" ><br><br>
<input type="submit" value="Submit" >
</form>
</body>
</html>
.js script:
function verifyUrl(){
var page_id=document.getElementById("url").value;
if(page_id){
var i=page_id.lastIndexOf('/');
var q=page_id.indexOf('?');
var id=0;
if (q>0){
id=page_id.substring(i,q);
}else{
id=page_id.substr(i,id.length);
}
alert(id);
FB.init({
appId : <myappid>,
xfbml : true,
version : 'v2.3'
});
FB.api(id,function(response){
if (!response || response.error) {
alert('Error occured');
} else {
alert('Response ID: ' + response.id);
}
});
}
+3
source to share
No one has answered this question yet
Check out similar questions: