Facebook Login Using Graph Api
I want to have facebook login using graph Api because I want user_birthday and user_location. Before I was using this link to login: http://www.androidhive.info/2012/03/and
Solution 1:
I'm not really sure if getBirthday()
, getLocation()
are the valid methods, but you can directly access these properties as-
get_birthday = (String) user.getProperty("birthday");get_location = (String) user.getProperty("location").getProperty("name");
I'm also not really sure user.getProperty("location").getProperty("name")
is valid thing to do, actually the response of location is of form:
"location":{"id":123456789,"name":"Blah"}
This should get you the birthday and location.
Also, check if you can see the bday and location permission granted or not in the app settings
Solution 2:
This is what I want..I hope it would be helpful to others...
publicvoidreadData(){
if (Session.getActiveSession() == null
|| Session.getActiveSession().isClosed()) {
Session.openActiveSession(this, true, newStatusCallback() {
@Overridepublicvoidcall(Session session, SessionState state,
Exception exception) {
System.out.println("State= " + state);
if (session.isOpened()) {
System.out.println("Token=" + session.getAccessToken());
if(session.getAccessToken() != null){
sharedPrefernces();
}
Request.executeMeRequestAsync(session, newRequest.GraphUserCallback() {
publicvoidonCompleted(GraphUser user, Response response) {
if (response != null) {
Log.i("Graphresponse", response.toString());
try{
get_id = user.getId();
get_name = user.getName();
get_gender = (String) user.getProperty("gender");
get_email = (String) user.getProperty("email");
get_birthday = user.getBirthday();
get_locale = (String) user.getProperty("locale");
get_location = user.getLocation().toString();
URL img_value = null;
img_value = newURL("http://graph.facebook.com/"+get_id+"/picture?type=large");
mImage = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
Log.d("GraphSelected", get_id + " " +
get_name + " " +
get_gender + " " +
get_email + " " +
get_birthday + " " +
get_locale + " " +
get_location);
} catch(Exception e) {
e.printStackTrace();
Log.d("GraphException", e.getMessage());
}
}
}
});
}
if (exception != null) {
System.out.println("Some thing bad happened!");
exception.printStackTrace();
}
}
});
}
}
Post a Comment for "Facebook Login Using Graph Api"