【发布时间】:2026-02-22 00:20:05
【问题描述】:
我一直致力于获取一个用于从服务器检索信息的 JSON 对象,并且我成功地解析了它。但是我被赋予了解析从 graph.facebook.com 获得的 JSON 对象的任务。但是当我尝试解析它时,它会显示这样的错误
error OAuthException (#210) Subject must be a page"。
我不知道为什么会出现此错误。是否可以从 graph.facebook.com 获取 JSON。 This 页面以 JSON 格式检索信息。但我无法解析它。我的解析代码是这样的。
Parser.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
// constructor
public JSONParser() {
}
public JSONObject getJSONFromUrl(String url) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
// is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
System.out.print(jObj.toString());
// return JSON String
return jObj;
}
}
请告诉我我能做些什么来解决这个问题。我非常需要它。
【问题讨论】:
-
向我们展示您为 json 访问的 URL。
-
好吧,我想我明白了。您正在使用 POST 获取 GET 类型的 URL。将您的 HTTP POST 更改为 HttpGet。
-
@MurtazaHussain: graph.facebook.com/fundamentalalvarado/…
-
阅读我的第二条评论。我希望它有所帮助。
-
是的。知道了。谢谢。你救了我。
标签: android parsing android-parser