m trying fetch all photos from perticular album from fac开发者_JAVA技巧ebook in android , i am using facebook android sdk to do the task but the problem is , i don't know what url request is required to access the photos inside album ?
https://graph.facebook.com/ALBUM_ID/photos
If it's for a particular person then:
https://graph.facebook.com/me/albums/
And then choose the album id and then use the first call
EDIT
You will also need to give permission while creating Facebook object in the Permission String array also need to add user_photos
to be able to load photos
Code Worked for Me.
I have two function - one is to get Album id and anther one is just retrieving all images from that particular album.
First use test()
function and then use 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();
}
}
}
Now use 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;
}
}
精彩评论