我想获取用户的 facebook 个人资料图片 url,下面是代码。
代码 :
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
StringBuilder res = new StringBuilder();
// fetch user profile picture url
URL url = null;
HttpURLConnection httpconn = null;
String strUrl = "http://graph.facebook.com/"
+ fbuser.getFacebookId()
+ "/picture?width=350&height=350";
try {
url = new URL(strUrl);
httpconn = (HttpURLConnection) url
.openConnection();
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
if (httpconn.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader input = new BufferedReader(
new InputStreamReader(httpconn
.getInputStream()));
String strLine = null;
while ((strLine = input.readLine()) != null) {
res.append(strLine);
}
input.close();
}
Log.e(TAG, "res : " + res);
JSONObject imageUrlObject = new JSONObject(
res.toString());
fbuser.setImageUrl(imageUrlObject
.getJSONObject("picture")
.getJSONObject("data")
.getString("url"));
// Call a method of an Activity to notify
// user info is received
((RS_LoginActivity) RS_Facebook.this.activity)
.FacebookUserInfoReceived();
// call login api
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
thread.start();
我记录了字符串响应,下面是该响应的屏幕截图。
知道为什么会这样吗?