I've this simple problem: I'm trying to implement a simple login with FB SDK 3.5 on android. I need the user to click on a normal button (no FBLoginButton) and get the email.
Until now I can handle the login with basic permissions provided by FB SDK, but I'm not able to request additional permission to the user.
I've read these answers on StackOverflow:
I've read this tutorial on FB pages:
Until now I have this code "working" ONLY for basic info (default info provided by FB).
FacebookLogin.activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_facebook_login);
pref = setApplicationContext().getSharedPreferences(MainActivity.SHARED_PREFERENCES, 0); // 0 for private mode
if (internetConnection()) {
// start Facebook Login
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(final Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
**// TRYING TO ADD NEW PERMISSIONS but doesn't work**
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(FacebookLogin.this, **PERMISSIONS**);
session.requestNewReadPermissions(newPermissionsRequest);
// riquest /me API
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) {
Editor pref_editor = pref.edit();
// token
pref_editor.putString(PREF_FB_ACCESS_TOKEN, session.getAccessToken());
// DEBUG
Log.i(LOG_ACTIVITY, "FB_token: "+session.getAccessToken());
Log.i(LOG_ACTIVITY, "FB_permissions: "+ session.getPermissions());
// user_id
pref_editor.putString(PREF_FB_USER_ID, user.getId());
// email
//pref_editor.putString(PREF_FB_USER_EMAIL,);
pref_editor.commit();
}
}
}).executeAsync();
Intent intent = new Intent(FacebookLogin.this, AfterLogin.class);
intent.putExtra(LOGIN_ORIGIN, "facebook");
startActivity(intent);
finish();
}
if (session.isClosed()){
// do nothing.FB call to FBapp
}
}
});
}
else {
Toast.makeText(getApplicationContext(), "error: no internet", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(FacebookLogin.this, MainActivity.class);
startActivity(intent);
finish();
}
}
Also I have the onActivityResult method inside the class/activity
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
Is there someone that knows how to fix it?
Thanks in advance.