我想在Java中使用FQL从任何页面中提取页面名称,喜欢,talking_about_count和页面信息等数据。我写了如下代码:
public static void main(String[] args) {
// TODO Auto-generated method stub
String STR_FACEBOOK_FQL_URL = "https://api.facebook.com/method/fql.query?query=";
String STR_FACEBOOK_RETURN_FORMAT = "&format=json";
String STR_FACEBOOK_ACCESS_TOKEN = "&access_token=";
String FQL_GET_QUERY= "SELECT name,likes,about FROM page WHERE id={page-id}";
String encodedQuery;
try
{
encodedQuery = URLEncoder.encode(FQL_GET_QUERY, "UTF-8");
String faceBookURL = STR_FACEBOOK_FQL_URL + encodedQuery +
STR_FACEBOOK_RETURN_FORMAT
+ STR_FACEBOOK_ACCESS_TOKEN ;
URL url = new URL(faceBookURL);
InputStream is = url.openStream();
JSONTokener tok = new JSONTokener(is);
JSONObject result = new JSONObject(tok);
System.out.println(result.toString());
is.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
但这显示错误如:
{"request_args":[{"value":"fql.query","key":"method"},{"value":"SELECT likes,name,about FROM page WHERE uid=me()","key":"query"},{"value":"json","key":"format"},{"value":"id|secret","key":"access_token"}],"error_code":602,"error_msg":"likes is not a member of the page table."}
有人可以告诉我,这段代码有什么不对吗?
答案 0 :(得分:0)
首先,请不要使用已弃用的端点:
String STR_FACEBOOK_FQL_URL = "https://graph.facebook.com/fql?q=";
是现在的方式。您为page
表使用了不存在的字段(请参阅https://developers.facebook.com/docs/reference/fql/page/)。 likes
需要替换为fan_count
:
String FQL_GET_QUERY= "SELECT name,fan_count,about FROM page WHERE id={page-id}";