从Android应用程序中的FQL查询中提取信息
作者:互联网
我正在尝试将我上传的视频的视频ID和其他信息存储在android中的不同字符串中.现在,我创建了一个fql查询来获取视频详细信息.我正在使用json解析来提取像这样的值-
String fqlQuery = "SELECT vid, owner, title, description,updated_time, created_time FROM video WHERE owner=me()";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
Request request = new Request(session,"/fql",params,HttpMethod.GET,new Request.Callback()
{
public void onCompleted(Response response)
{
try
{
JSONObject json = Util.parseJson(response.toString());
JSONArray data = json.getJSONArray( "data" );
for ( int i = 0, size = data.length(); i < size; i++ )
{
JSONObject getVideo = data.getJSONObject( i );
userNameView.setText(getVideo.getString("vid"));
}
}
catch(Exception e){userNameView.setText(e.toString());}
}
});
Request.executeBatchAsync(request);
}
});
但这让我感到异常-
org.json.JSONException:Unterminated object at character 25 of
{Response:responseCode:200,graphObject:GraphObject{graphObjectClass=GraphObject,state=
{“data”:[{“owner”:…}]}}}
这是我第一次使用android,facebook sdk以及json解析,因此我将非常高兴提供所提供的任何帮助.谢谢.
解决方法:
queryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String fqlQuery = "SELECT uid, name, pic_square, status FROM user WHERE uid IN " +
"(SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 25)";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
Request request = new Request(session,
"/fql",
params,
HttpMethod.GET,
new Request.Callback(){
@SuppressWarnings("deprecation")
public void onCompleted(Response response) {
GraphObject graphObject = response.getGraphObject();
if (graphObject != null)
{
if (graphObject.getProperty("data") != null)
{
try {
String arry = graphObject.getProperty("data").toString();
JSONArray jsonNArray = new JSONArray(arry);
for (int i = 0; i < jsonNArray.length(); i++) {
JSONObject jsonObject = jsonNArray.getJSONObject(i);
String name = jsonObject.getString("name");
String uid = jsonObject.getString("uid");
String pic_square = jsonObject.getString("pic_square");
String status = jsonObject.getString("status");
Log.i("Entry", "uid: " + uid + ", name: " + name + ", pic_square: " + pic_square + ", status: " + status);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
});
Request.executeBatchAsync(request);
}
});
标签:facebook,facebook-fql,android 来源: https://codeday.me/bug/20191031/1976380.html