Issues in downloading Facebook profile picture in my app - android

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.

Related

Write exif data to android video files

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
}

Approach to log in system using Node.js and Passport via Android

I am currently developing a web service that is using Node.js/ExpressJS and Passport for the login system. Everything is working fine on the web.
I would like to create an Android App that can be used to login to the server via httppost/JSON and get access to the user profile and all its variables.
Currently I am using a very stupid and unsecure approach.
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Duan duan = ((Duan)getApplicationContext());
String output = "";
try {
output = new LoginTask().execute(jsonURL).get();
Log.v("JSON: ", output);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONObject jsonObject;
try {
jsonObject = new JSONObject(output);
String username = jsonObject.getString("username");
String user_id = jsonObject.getString("_id");
duan.setUserId(user_id);
duan.setUsername(username);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
As you can see, I am storing the _id and username field into a singleton that can be access across the application.
Is there a better and more secure way to program a log in system on android that works with Node.js and Passport?
Thanks,
Dennis

How to get images from facebook album

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");

facebook status update

I am having problem in updating status on facebook. I am using Facebook sdk, the problem is that my status is getting post but not showing text. Here is my code ---->
public class NetRockersUpdate extends AsyncTask{
#Override
protected String doInBackground(String... msg) {
// TODO Auto-generated method stub
nra = (NetRockersApp)getApplication();
String result = "Status Posted Successfully";
Bundle parameters = new Bundle();
parameters.putString("test", msg[0]);
parameters.putString("method", "stream.publish");
try {
nra.facebook.request(parameters);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}
Check all the below post : I explained how to Post on User wall:
Post on User's Facebook Wall
Post to user Wall with Description,title,caption and link
Post on Wall..
you don't have a "message" key in your parameter.

fetch photos from facebook album in android

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;
}
}

Categories

Resources