My aim is to retrieve friend list from facebook.I have the javaScript code.But when I try to run the code, it gives me following error:
Success Object {error_code: "12", error_msg: "REST API is deprecated for versions v2.1 and higher", request_args: Array[8]}
Here is the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title> 'FbFriends'</title>
<script src=".js"></script>
<script src=".js"></script>
<!--<link rel="stylesheet" type="text/css" href="styles.css">-->
</head>
<body>
<div id="fb-root"></div>
<script src=".js"></script>
<fb:login-button autologoutlink="true" scope="email,public_profile,user_friends" size="large"></fb:login-button>
<script>
FB.init({
appId : 'App Id',
status : false, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.getLoginStatus(function(response) {
if (response.authResponse) {
//getting current logged in user's id from session object
var globaluserid=response.authResponse.userID;
console.log("login Status", +globaluserid);
//fetching friends uids from 'friend' table. We are using FB.api syntax
FB.api(
{
method: 'fql.query',
query: 'SELECT uid2 FROM friend WHERE uid1='+globaluserid
},
function(response) {
console.log('Success', response);
//once we get the response of above select query we are going to parse them
for(i=0;i<response.length;i++)
{
//fetching name and square profile photo of each friends
console.log("Now fetching name..");
FB.api(
{
method: 'fql.query',
query: 'SELECT name,pic_square FROM user WHERE uid='+response[i].uid2
},
function(response) {
//creating img tag with src from response and title as friend's name
htmlcontent='<img src='+response[0].pic_square+' title='+response[0].name+' />';
//appending to div based on id. for this line we included jquery
$("#friendslist").append(htmlcontent);
}
);
}
}
);
}
});
</script>
<div id="fb-root"></div>
<table width="100%" border="0">
<tr>
<td align="left">
<div id="friendslist"> Priyanka </div>
</td>
</tr>
</table>
</body>
</html>
My aim is to retrieve friend list from facebook.I have the javaScript code.But when I try to run the code, it gives me following error:
Success Object {error_code: "12", error_msg: "REST API is deprecated for versions v2.1 and higher", request_args: Array[8]}
Here is the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title> 'FbFriends'</title>
<script src="http://connect.facebook/en_US/all.js"></script>
<script src="http://code.jquery./jquery-latest.js"></script>
<!--<link rel="stylesheet" type="text/css" href="styles.css">-->
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook/en_US/all.js"></script>
<fb:login-button autologoutlink="true" scope="email,public_profile,user_friends" size="large"></fb:login-button>
<script>
FB.init({
appId : 'App Id',
status : false, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.getLoginStatus(function(response) {
if (response.authResponse) {
//getting current logged in user's id from session object
var globaluserid=response.authResponse.userID;
console.log("login Status", +globaluserid);
//fetching friends uids from 'friend' table. We are using FB.api syntax
FB.api(
{
method: 'fql.query',
query: 'SELECT uid2 FROM friend WHERE uid1='+globaluserid
},
function(response) {
console.log('Success', response);
//once we get the response of above select query we are going to parse them
for(i=0;i<response.length;i++)
{
//fetching name and square profile photo of each friends
console.log("Now fetching name..");
FB.api(
{
method: 'fql.query',
query: 'SELECT name,pic_square FROM user WHERE uid='+response[i].uid2
},
function(response) {
//creating img tag with src from response and title as friend's name
htmlcontent='<img src='+response[0].pic_square+' title='+response[0].name+' />';
//appending to div based on id. for this line we included jquery
$("#friendslist").append(htmlcontent);
}
);
}
}
);
}
});
</script>
<div id="fb-root"></div>
<table width="100%" border="0">
<tr>
<td align="left">
<div id="friendslist"> Priyanka </div>
</td>
</tr>
</table>
</body>
</html>
Share
Improve this question
asked Aug 11, 2014 at 10:26
Priyanka JagdalePriyanka Jagdale
311 gold badge1 silver badge2 bronze badges
2 Answers
Reset to default 1The method fql.query
is deprecated. See https://developers.facebook./docs/javascript/reference/FB.api/ for the current usage.
You can run FQL queries with Graph API versions up to v2.0 like this:
FB.api('/fql?q={your_url_encoded_query}', 'get', function(response) {
...
});
You'll have troubles getting the list of friends for apps other than Graph API v1.0, as you're hopefully aware.
Also, you can bine you FQL queries into one:
select uid, name, pic_square from user where uid in (select uid2 from friend where uid1=me())
To get the friends list you use /me/friends. That will return all friends that are also using the app. There is no way to get all friends.