获取 Facebook 专辑封面照片 - Android
Fetch Facebook album cover photo - Android
我尝试从 Facebook 获取专辑数据,我使用 this 方法获取专辑封面照片。我得到这样的回应;
{Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"FACEBOOK_NON_JSON_RESULT":"����\u0000\u0010JFIF\u0000\u0001\u0002\u0000\u0000\u0001\u0000\u0001\u0000\u0000��\u0000�Photoshop"}}, error: null, isFromCache:false}
这是什么意思?如何获取图像 url 或图像?
代码在这里:
for(final FbAlbumItem f: albums){
Bundle params = new Bundle();
params.putString("type", "small");
new Request(
Session.getActiveSession(),
"/"+f.getAlbumId()+"/picture",
params,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
Log.i("SocialManager", "" + response);
JSONObject obj = response.getGraphObject().getInnerJSONObject();
try {
JSONObject o = obj.getJSONObject("albums").getJSONObject("data");
String url = o.getString("url");
f.setImageUrl(url);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
).executeAsync();
FbAlbumItem :
String albumId;
String albumName;
String albumCover;
String imageUrl;
你本可以这样做的。
final Session session = Session.getActiveSession();
if (session.isOpened()) {
final String authToken = session.getAccessToken();
// saveToPreferences(ApplicationData.FB_TOKEN, authToken);
Bundle params = new Bundle();
params.putBoolean("redirect", false);
params.putString("height", "400");
params.putString("type", "normal");
params.putString("width", "400");
/* make the API call */
new Request(
session,
"/me/albums/{album-id}",
params,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
//cover_photo_fetch = response.cover_photo.toString();
Log.d("Picture", response.toString());
try {
userModel = UserModel.getInstance(mContext);
personPhotoUrl = response.getGraphObject().getInnerJSONObject().getJSONObject("data").getString("url");
} catch (JSONException e) {
e.printStackTrace();
}
}
}
).executeAsync();
先决条件 - user_photos
非 public 相册的权限
通过cover_photo
字段获取
me/albums/album_id?fields=cover_photo
文档参考 here
已解决。我用我的方法做了一些改变。添加此参数
Bundle params = new Bundle();
params.putBoolean("redirect", false);
感谢启发。
我尝试从 Facebook 获取专辑数据,我使用 this 方法获取专辑封面照片。我得到这样的回应;
{Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"FACEBOOK_NON_JSON_RESULT":"����\u0000\u0010JFIF\u0000\u0001\u0002\u0000\u0000\u0001\u0000\u0001\u0000\u0000��\u0000�Photoshop"}}, error: null, isFromCache:false}
这是什么意思?如何获取图像 url 或图像? 代码在这里:
for(final FbAlbumItem f: albums){
Bundle params = new Bundle();
params.putString("type", "small");
new Request(
Session.getActiveSession(),
"/"+f.getAlbumId()+"/picture",
params,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
Log.i("SocialManager", "" + response);
JSONObject obj = response.getGraphObject().getInnerJSONObject();
try {
JSONObject o = obj.getJSONObject("albums").getJSONObject("data");
String url = o.getString("url");
f.setImageUrl(url);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
).executeAsync();
FbAlbumItem :
String albumId;
String albumName;
String albumCover;
String imageUrl;
你本可以这样做的。
final Session session = Session.getActiveSession();
if (session.isOpened()) {
final String authToken = session.getAccessToken();
// saveToPreferences(ApplicationData.FB_TOKEN, authToken);
Bundle params = new Bundle();
params.putBoolean("redirect", false);
params.putString("height", "400");
params.putString("type", "normal");
params.putString("width", "400");
/* make the API call */
new Request(
session,
"/me/albums/{album-id}",
params,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
//cover_photo_fetch = response.cover_photo.toString();
Log.d("Picture", response.toString());
try {
userModel = UserModel.getInstance(mContext);
personPhotoUrl = response.getGraphObject().getInnerJSONObject().getJSONObject("data").getString("url");
} catch (JSONException e) {
e.printStackTrace();
}
}
}
).executeAsync();
先决条件 - user_photos
非 public 相册的权限
通过cover_photo
字段获取
me/albums/album_id?fields=cover_photo
文档参考 here
已解决。我用我的方法做了一些改变。添加此参数
Bundle params = new Bundle(); params.putBoolean("redirect", false);
感谢启发。