在我的应用程序中,我让用户从Facebook上传照片。所以首先我用以下内容获取所有用户相册:
new Request(session, "/me/albums", null, HttpMethod.GET, new Request.Callback() {
public void onCompleted(Response response) {
}
};
然后我使用适配器在GridView中显示每个专辑,所以在getView方法中我调用/{album-id}/picture,但我不知道如何解析响应。我与Response对象有什么关系,在ImageView中显示图像?有没有更好的方法呢?
这是我提出请求的方式
Bundle params = new Bundle();
params.putString("type", "thumbnail");
String albumid = albums.get(position);
new Request(session, "/"+ albumid +"/picture",
params, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
ViewHolder holder = new ViewHolder();
}
}
).executeAsync();
这就是我得到的:
{响应:responseCode:200,graphObject: GraphObject {graphObjectClass = GraphObject, 状态= {" FACEBOOK_NON_JSON_RESULT":" \ u0000的\ u0010JFIF \ u0000的\ U0001 \ U0002 \ u0000的\ u0000的\ U0001 \ u0000的\ U0001 \ u0000的\ u0000的\ u0000的\ U0004 * \ u0000的\ U0002 \ u001cICC_PROFILE \ u0000的\ U0001 \ U0001 \ u0000的\ u0000的\ U0002"}}, 错误:null,isFromCache:false}
答案 0 :(得分:1)
要获取脸谱,请使用此
Bundle params = new Bundle();
//params.putString("fields", "photos.limit(10),name,count");
params.putString("access_token", facebook.getAccessToken());
params.putString("limit", "1000");
//me = new JSONObject(facebook.request("me/albums",params ,"GET"));
System.out.println("params are: "+params);
if(facebook.getAccessToken()!= null)
{
me = new JSONObject(facebook.request("me/albums",params ,"GET"));
}
fbAlbumList.clear();
try {
//JSONObject jsonObject = new JSONObject(respons);
JSONArray jsonArray = me.getJSONArray("data");
for (int i = 0; i < jsonArray.length(); i++) {
FbAlbumBean bean = new FbAlbumBean();
bean.albumId = jsonArray.getJSONObject(i).getString("id");
bean.albumName = jsonArray.getJSONObject(i).getString("name");
if(i!=0)
{
bean.coverId = jsonArray.getJSONObject(i).getString("cover_photo");
bean.albumCount = jsonArray.getJSONObject(i).getInt("count")+"";
}
fbAlbumList.add(bean);
}
用于通过albumId获取照片
public void fetchPhotosFromAlbumId(final String album_id, Activity activity){
//new FetchAsyncTask().execute(album_id);
progressDialog1 = ProgressDialog.show(activity,"", "Please wait...");
System.out.println("progress dialog: "+progressDialog1);
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
JSONObject me;
try {
fbPhotosList.clear();
String offset1 = String.valueOf(offset+100);
Bundle params = new Bundle();
params.putString("limit", "1000");
params.putString("access_token", facebook.getAccessToken());
//me = new JSONObject(facebook.request("me/albums",params ,"GET"));
me = new JSONObject(facebook.request(album_id+"/photos",params ,"GET"));
System.out.println(me);
JSONArray jsonArray = me.getJSONArray("data");
for (int i = 0; i < jsonArray.length(); i++) {
CameraRollBean bean = new CameraRollBean();
bean.filePath = jsonArray.getJSONObject(i).getString("source");
bean.showRight_IB = false;
fbPhotosList.add(bean);
}
System.out.println("size of fb album: "+fbAlbumList.size());
FbAlbumsScreen.fromFbScreen = true;
Intent intent = new Intent(_activity, CameraRollScreen.class);
intent.putExtra("album_id", album_id);
_activity.startActivity(intent);
if(progressDialog1!=null)
progressDialog1.cancel();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
progressDialog1.show();
}
答案 1 :(得分:0)
您最有可能将HTTP重定向返回到图片网址(例如,这可以在网站上的<img>
标记中使用)
Fields
No fields are returned, instead you will receive the image file itself.
您可能需要做的是专门请求封面照片,如下所示:
/<version>/<album id>?fields=cover_photo
- 获得ID后,您可以请求Photo object的详细信息,并从响应中获取最合适尺寸的源图像