【问题标题】:Facebook graph API fail to load resource bad request 400Facebook 图形 API 无法加载资源错误请求 400
【发布时间】:2015-08-28 01:29:35
【问题描述】:

我的controller.js 上有以下代码,当我从 Facebook Graph 2.4 请求时可以使用

request.open("GET","https://graph.facebook.com/v2.4/katyperry/posts?"+access_token,true);

但是,这只返回几个字段:messagestorycreated_timeid

我需要更多的字段:messagepicturelikescreated_timelinktypecommentsobject_id

所以我尝试了以下方法:

request.open("GET","https://graph.facebook.com/v2.4/katyperry?fields=posts.limit(2){message,picture,likes,created_time,link,type,comments,object_id}"+access_token,true);

最后一个发给我的错误:

加载资源失败:服务器响应状态为 400(错误请求)

我在 Graph API Explorer 上测试了请求的两个选项,它工作正常。我怎样才能得到那些额外的字段?我错过了什么?

我正在添加先例代码以显示 access_token 是如何构建的:

var appID ="138429819833219";
var appSecret ="dada0a4d7f7717b0d37fd637d9e1522a";

var accessTokenRq = makeHttpRequest();
var httpString = 'https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id='+appID+'&client_secret='+appSecret;

accessTokenRq.open("GET",httpString,true);
accessTokenRq.send(null);

var access_token;

accessTokenRq.onreadystatechange = function() {

  if (accessTokenRq.readyState == 4) {
    access_token = accessTokenRq.responseText;
    //alert("Hat geklappt - Trabajó :)");

    var request = makeHttpRequest();
    
// the following request works
    request.open("GET","https://graph.facebook.com/v2.2/katyperry/posts?"+access_token,true);


// next one don't - I checked inspector and access_token contains: 138429819833219|CewVrYOd86ctJ0HTP2X0XAS9m4o
    request.open("GET","https://graph.facebook.com/v2.4/katyperry?fields=posts.limit(2){message,picture,likes,created_time,link,type,comments,object_id}"+access_token,true);

【问题讨论】:

    标签: facebook-graph-api ionic-framework bad-request


    【解决方案1】:

    access_token 变量中包含什么?请求

    /katyperry?fields=posts.limit(2){message,picture,likes,created_time,link,type,comments,object_id}
    

    在 Graph API Explorer 中工作,所以我猜你的 access_token 变量只包含实际的访问令牌,而不是参数键/值对。

    这个

    request.open("GET","https://graph.facebook.com/v2.4/katyperry?fields=posts.limit(2){message,picture,likes,created_time,link,type,comments,object_id}&access_token="+access_token,true);
    

    希望那时可以工作。

    【讨论】:

    • 我在原始问题中添加了先例代码,并与检查员检查了 access_token 的值,似乎没问题
    • 试试我写的请求。您的请求在访问令牌本身之前缺少 &access_token= 部分
    • 托比,我试过你的代码,它没有用,抛出我:“无效的 OAuth 访问令牌签名,OAuthException”,190 作为交换,我玩弄它并让它工作,它似乎是一个语法错误,最后添加解决方案
    【解决方案2】:

    错误是语法,正确代码如下:

    request.open("GET","https://graph.facebook.com/v2.4/katyperry/posts?limit=2&fields=message,picture,likes,created_time,link,type,comments,object_id&"+access_token,true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-31
      • 1970-01-01
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多