I am trying to use the Javascript SDK of Facebook API, in order to verify whether a Facebook page (not a profile, only a page of a place) exists or not. I use two separate files, one HTML with a simple form in it and a script that makes a call to the facebook api. However the FB.api method doesn't seem to return anything. I don't have much experience using the api, so I would appreciate any help.
The code of the html file:
<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>
The .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);
}
});
}