【发布时间】:2010-09-14 06:52:20
【问题描述】:
我正在尝试从 android 的 facebook 获取特定相册中的所有照片,我正在使用 facebook android sdk 来完成任务,但问题是,我不知道访问相册中的照片需要什么 url 请求?
【问题讨论】:
我正在尝试从 android 的 facebook 获取特定相册中的所有照片,我正在使用 facebook android sdk 来完成任务,但问题是,我不知道访问相册中的照片需要什么 url 请求?
【问题讨论】:
https://graph.facebook.com/ALBUM_ID/photos
如果是针对特定的人,那么:
https://graph.facebook.com/me/albums/
然后选择专辑id然后使用第一次调用
编辑
您还需要在权限字符串数组中创建 Facebook 对象时授予权限,还需要添加 user_photos 才能加载照片
【讨论】:
代码为我工作。
我有两个功能 - 一个是获取专辑 ID,另一个是从该特定专辑中检索所有图像。
先使用test()函数,再使用downloadpic()。
public void test()
{
facebook.getAccessToken();
JSONArray albumss=null;
String response = null;
try {
response = facebook.request("me/albums");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONObject json = null;
try {
json = Util.parseJson(response);
} catch (FacebookError e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONArray albums = null;
try {
albums = json.getJSONArray("data");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int i =0; i < albums.length(); i++) {
JSONObject album = null;
try {
album = albums.getJSONObject(i);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
//Here I have selected Profile pic album.
if (album.getString("type").equalsIgnoreCase("profile")) {
// JSONArray al=null;
wallAlbumID = album.getString("id");
// Now you have album id in wallAlbumID(global varible).
Log.d("JSON", wallAlbumID);
break;
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
现在使用downloadpic():
void downloadpic( )
{
facebook.getAccessToken();
String response = null;
try {
response = facebook.request(wallAlbumID+"/photos");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONObject json = null;
try {
json = Util.parseJson(response);
} catch (FacebookError e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONArray photos = null;
try {
photos = json.getJSONArray("data");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int i =0; i < photos.length(); i++) {
JSONObject a = null;
try {
a = photos.getJSONObject(i);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String testing = null;
try {
testing = a.getString("source");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
\
URL value=null;
try {
value=new URL(testing);
//Now you have URL of that particular image use it in your way
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
【讨论】: