Javascript 对于v2.1及更高版本,不推荐使用REST API
我的目标是从facebook检索好友列表。我有javaScript代码。但当我尝试运行代码时,它会给我以下错误: 成功对象{error_code:“12”,error_msg:“REST API不推荐用于v2.1及更高版本”,request_args:Array[8]} 代码如下:Javascript 对于v2.1及更高版本,不推荐使用REST API,javascript,facebook,rest,facebook-graph-api,Javascript,Facebook,Rest,Facebook Graph Api,我的目标是从facebook检索好友列表。我有javaScript代码。但当我尝试运行代码时,它会给我以下错误: 成功对象{error_code:“12”,error_msg:“REST API不推荐用于v2.1及更高版本”,request_args:Array[8]} 代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <ba
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title> 'FbFriends'</title>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script src="http://code.jquery.com/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.net/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>
“朋友”
FB.init({
appId:“应用程序Id”,
状态:false,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
FB.getLoginStatus(函数(响应){
if(response.authResponse){
//从会话对象获取当前登录用户的id
var globaluserid=response.authResponse.userID;
日志(“登录状态”+globaluserid);
//正在从“friend”表获取friends UID。我们正在使用FB.api语法
FB.api(
{
方法:“fql.query”,
查询:“从uid1=”的好友中选择uid2+globaluserid
},
功能(响应){
console.log('Success',response);
//一旦我们得到上述select查询的响应,我们将对它们进行解析
对于(i=0;i方法fql.query
已弃用。有关当前用法,请参阅
您可以使用最高达v2.0的Graph API版本运行FQL查询,如下所示:
FB.api('/fql?q={your_url_encoded_query}', 'get', function(response) {
...
});
希望您知道,在获取Graph API v1.0以外的应用程序的好友列表时会遇到困难
此外,您还可以将FQL查询组合为一个查询:
select uid, name, pic_square from user where uid in (select uid2 from friend where uid1=me())
要获取您使用/me/friends的好友列表,将返回所有同时使用该应用的好友。无法获取所有好友