javascript - v2.1 及更高版本已弃用 REST API

标签 javascript facebook rest facebook-graph-api

我的目标是从 facebook 检索好友列表。我有 javaScript 代码。但是当我尝试运行代码时,它给了我以下错误:

成功对象 {error_code: "12", error_msg: "REST API is deprecated for versions v2.1 and higher", request_args: Array[8]}

代码如下:

<!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>

最佳答案

方法 fql.query 已弃用。参见 https://developers.facebook.com/docs/javascript/reference/FB.api/对于当前的使用情况。

您可以使用高达 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())

关于javascript - v2.1 及更高版本已弃用 REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25241099/

相关文章:

javascript - IntelliJ 的服务器端 JS 覆盖率

JavaScript 带参数函数的问题

ruby-on-rails - 如何在 Ruby on Rails 应用程序中处理 RESTful URL 参数?

rest - 通过 Rest API 更新 redmine 的 issue 日志

javascript - typescript - ts(7053) : Element implicitly has an 'any' type because expression of type 'string' can't be used to index

javascript - Ajax-ing JavaScript 变量到 Django View 获取 : AttributeError: 'WSGIRequest' object has no attribute 'data'

iphone - 如何在 iPhone 网络应用程序中使用 Facebook Connect

ios - 在 iOS 上查找 Facebook SDK 版本

javascript - 替换 RSS 阅读器 (InoReader) 中的 Facebook 缩略图

java - Tomcat : web application java class files/jar location