I am trying to login with facebook using android sdk 4.7. I have tried the following link http://www.theappguruz.com/blog/android-facebook-integration-tutorial http://www.an
First Go to https://developers.facebook.com/ ,Login and select My Apps and create a App.
Follow the given instruction on by one properly.
Give packagename and packagename.ActivityName, select use App name then save it.
Generate Hash Key (Download OpenSSL) and (Java JDK). - For windows!
Extract the OpenSSL stuffs to C:\OpenSSL
Go to CMD prompt set the current path to JDK's bin folder.
Then use this command :
keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Shredder\.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary | "C:\OpenSSL\bin\openssl" base64
Make sure you are using proper Paths like UserAccountName etc.Mine was shredder.After that use Password : 123456.
Paste the hashKey to the required field. Then follow along....
Use the following code if required.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign__in);
String fb_id ="";
String fb_fName ="";
String fb_lName ="";
String fb_email ="";
String EMAIL = "email";
CallbackManager callbackManager = CallbackManager.Factory.create();
final LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList(EMAIL));
loginButton.registerCallback(callbackManager, new FacebookCallback() {
@Override
public void onSuccess(LoginResult loginResult) {
String userId = loginResult.getAccessToken().getUserId();
GraphRequest graphRequest = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
getUserFbUserInfo (object);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "first_name,last_name,email,id");
graphRequest.setParameters(parameters);
graphRequest.executeAsync();
Intent it = new Intent(getApplicationContext(), Home_Page.class);
it.putExtra("fbLogin", true);
startActivity(it);
}
@Override
public void onCancel() {
// App code
}
@Override
public void onError(FacebookException exception) {
// App code
}
});
}
private void getUserFbUserInfo(JSONObject object) {
try {
fb_email = object.getString("email");
fb_fName = object.getString("first_name");
fb_lName = object.getString("last_name");
fb_id = object.getString("id");
}
catch (JSONException e) {
e.printStackTrace();
}
}
@Override
protected void onActivityResult ( int requestCode, int resultCode, Intent data){
callbackManager.onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
}