提前致谢。
我在我的controller.js上有以下代码,当我从Facebook Graph 2.4请求时可以使用
request.open("GET","https://graph.facebook.com/v2.4/katyperry/posts?"+access_token,true);
但是这只返回几个字段:message,story,created_time和id。
我还需要一些额外的字段:message,picture,likes,created_time,link,type,comments和object_id。
所以我尝试了以下内容:
request.open( “GET”, “https://graph.facebook.com/v2.4/katyperry?fields=posts.limit(2) {消息,图画,喜欢,CREATED_TIME,链接,类型,注释的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);
答案 0 :(得分:1)
access_token
变量中包含哪些内容?请求
/katyperry?fields=posts.limit(2){message,picture,likes,created_time,link,type,comments,object_id}
在Graph API资源管理器中工作,所以我猜你的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);
当然应该有用。
答案 1 :(得分:-1)
错误是语法,正确的代码如下:
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);