m trying fetch all photos from perticular album from facebook 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;
}
}
Related
I have implemented facebook sdk in my android application and I have spent past 3hrs in downloading profile picture from facebook and yet i'm not successful in downloading it.
This is my code.
try {
String user = Facebuk.fb.request("me");
jsonObject = Util.parseJson(user);
String id = jsonObject.optString("id");
name = jsonObject.optString("name");
URL img_url = new URL("http://graph.facebook.com/" + id
+ "/picture?type=large");
dp = BitmapFactory.decodeStream(img_url.openConnection().getInputStream());
if (dp == null)
Log.i("", "afafaffgwgwgwg");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FacebookError e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
i get notified from the logcat that BitmapFactory.decodestream returns null
There were similar posts asked in Stack Overflow and there solution didn't workout for me.. please help me out.
Try using AQuery library which provides callback in which u get bitmap.
I am extracting metadata information (Exif infor) by using Id3 library in android, but I am getting null pointer exception and getting null in log Message it is a reason because value in src_set is null .I am not getting why it is returning null. my code is :
File src = new File(pathdata);
MusicMetadataSet src_set = null;
try {
src_set = new MyID3().read(src);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // read metadata
if (src_set == null) // perhaps no metadata
{
Log.i("NULL", "NULL");
}
else
{
try{
IMusicMetadata metadata = src_set.getSimplified();
String artist = metadata.getArtist();
String album = metadata.getAlbum();
String song_title = metadata.getSongTitle();
Number track_number = metadata.getTrackNumber();
Log.i("artist", artist);
Log.i("album", album);
}catch (Exception e) {
e.printStackTrace();
}
File dst = new File(pathdata);
MusicMetadata meta = new MusicMetadata("name");
meta.setAlbum("Chirag");
meta.setArtist("CS");
try {
new MyID3().write(src, dst, src_set, meta);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ID3WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // write updated metadata
}
I am getting a duration of my audio file , convert it to int , then convert int to string and then string to something like this 00:32 . Converted string is correct, but then is a problem with convert that string to data
Here is my code:
File file = new File(Environment.getExternalStorageDirectory()+"/MyImages/.audio1.wav");
MediaPlayer mp = new MediaPlayer();
FileInputStream fs = null;
FileDescriptor fd = null;
try {
fs = new FileInputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fd = fs.getFD();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mp.setDataSource(fd);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int length = mp.getDuration()/1000;
mp.release();
String audiotime = String.valueOf(length);
SimpleDateFormat sdf = new SimpleDateFormat("mmss");
try {
Date d = sdf.parse(audiotime);
textView1.setText(audiotime);
} catch (ParseException ex) {
}
Two things, most important, you use the original String as text for your TextView. You should do something like textView1.setText(d.toString());
Secondly, you should use "mm:ss" as your format, instead of "mmss".
Note you could also use the format function of SimpleDateFormat. This will return a StringBuffer, which might be more appropriate since you only need the String representation
source: android documentation
I'm trying to save a custom object when I click a menu item. The problem is its crashing. Before we start, when I try to read that data in another activity, that also crashes. Here is my code where I'm trying to save the data:
Here's a pastebin link.
my write function in the menu
myInfo.setOnMenuItemClickListener(new OnMenuItemClickListener()
{
public boolean onMenuItemClick(MenuItem item)
{
Intent ourIntent = new Intent(Results.this, listTimes.class);
ourIntent.putExtra("Meeting", meetingObj);
try {
fos = new FileOutputStream(filename);
oos = new ObjectOutputStream(fos);
oos.writeObject(businesses.get(positionChecked));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
oos.close();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//startActivity(ourIntent);
return true;
}
// My read function
private void getData()
{
try {
fis = openFileInput(filename);
ois = new ObjectInputStream(fis);
business = (Business) ois.readObject();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (StreamCorruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
ois.close();
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I have albumID,I did the following code but not able to get the result (photos).
I think m missing something in facebook.request
try {
//wallAlbumID is variable having album id.
response = facebook.request("me/album."+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();
}
looking for code in response.
If you already know your Album ID, you don't have to add me/albums/ to your request. Try this:
response = facebook.request(wallAlbumID+"/photos");