2011-10-02 73 views
0

我想通过jQuery获取使用Facebook图形API的json数据。我正在使用下面的代码。我试图用$ .getJSON函数来获取JSON数据,但它显示在萤火如何从facebook图表api中获取数据jquery

NetworkError: 400 Bad Request - https://graph.facebook.com/me/home?access_token=mytoken 

这里是我的代码

<!DOCTYPE HTML> 
<html lang="en"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"> 
    </script> 
    <script type="text/javascript" src="script/script.js"></script> 
    <script> 
     $(function(){ 
      //$('fb').fbWall(); 
      var url = "https://graph.facebook.com/me/home?access_token=mytoken"; 
      var html = "<ul>"; 
      $.getJSON(url, function(json){ 
       //console.log(json); 
       $.each(json.data, function(i,fb){ 
        html += "<li>" + fb.id + "</li>"; 
       }); 
      }); 
      html += "</ul>"; 

      $('.fb').animate({opacity: 0}, 500, function() { 
       $('.fb').html(html); 
      }); 
      $('.fb').animate({opacity:1}, 500); 
     }); 
    </script> 
    <!-- <link type="text/css" rel="stylesheet" href="styles.css" /> --> 
    <style> 
     .fb { 
      width: 400px; height: 400px; 
      border:1px solid red; 
     } 
    </style> 
    <title>title</title> 
</head> 
<body> 
    <div class="fb"> 

    </div> 
</body> 
</html> 

我在哪里犯错这个错误?

+0

通过发布您的访问令牌,您授予所有人权限查看您的帐户详细信息 – bkaid

+0

您确定这是正确的访问令牌吗? –

+0

是的,它是正确的访问令牌。任何线索? – doforumda

回答

0

如果你去你直接发布的URL,它返回的错误:

{ 
    "error": { 
     "message": "(#606) Queries for multiple source_ids require a non-zero viewer that has granted read_stream permission", 
     "type": "OAuthException" 
    } 
} 

这意味着你需要提示read_stream权限读取用户的饲料。

+0

好吧,我将标记更改为这种格式“XXXXXXXXXXXXXXXXXXXX | JwbAtDcinTgJPpO3I_pcNOdd5gs”。 现在,当我在浏览器中使用此链接“https://graph.facebook.com/ID/feed?access_token=170270366392401|JwbAtDcinTgJPpO3I_pcNOdd5gs”时,它确实显示了所有提要,但是当我在代码中使用它时,它不显示任何事情。在Firebug它说 GET https://graph.facebook.com/xafarsaleem/feed?access_token=170270366392401|JwbAtDcinTgJPpO3I_pcNOdd5gs \t 200 OK 但没有得到任何JSON数据。 – doforumda