I am trying to implement fetch user data example give on developers.facebook.com It works fine on Emulator and displayes data in logcat but when i try it in real device it doesn't open screen for login thats why it directly writes message to Logcat "Logged out"( I guess that means state is closed) following is the code
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
userInfoTextView.setVisibility(View.VISIBLE);
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
// Display the parsed user info
buildUserInfoDisplay(user);
Log.d(TAG,"Data Displayed");
}
}
}).executeAsync();
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
userInfoTextView.setVisibility(View.INVISIBLE);
}
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fblogin, container, false);
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList("user_likes", "user_status","user_location","email","user_birthday"));
Log.d(TAG,"onCreateview");
userInfoTextView = (TextView) view.findViewById(R.id.userInfoTextView);
return view;
}
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
@Override
public void onResume() {
super.onResume();
// For scenarios where the main activity is launched and user
// session is not null, the session state change notification
// may not be triggered. Trigger it if it's open/closed.
Session session = Session.getActiveSession();
if (session != null &&
(session.isOpened() || session.isClosed()) ) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
private void buildUserInfoDisplay(GraphUser user) {
/*if(user.getLocation()!=null){
userInfo.append(String.format("ID: %s\n\n",
user.getLocation()));
}*/
//Log.d(TAG+" Location",user.getLocation().toString());
Map<String, String> map;
map = new HashMap<String, String>();
try {
map.put("ID", user.getId().toString());
map.put("email", user.getProperty("email").toString());
map.put("rel status", user.getProperty("relationship_status")
.toString());
map.put("name", user.getName().toString());
// - requires user_birthday permission
map.put("birthday", user.getBirthday().toString());
map.put("gender", user.getProperty("gender").toString());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
Log.d(TAG,"Info is: "+map);
}
}}
I have facebook app installed in device but it doesn't initiate login from that app also. do I have to add something different in order to get webview or login screen for login.
Note that this code works in emulator: Thanks for the help