Permalink
Browse files

Add Facebook Login

  • Loading branch information...
dragosholban committed Mar 13, 2018
1 parent 83b08b9 commit 0357dd7993b3a91bcffae5d0d54ae76887915b2f
@@ -1,13 +1,55 @@
package dragosholban.com.bestphotos;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
import java.util.Arrays;
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getName();
private CallbackManager callbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LoginButton loginButton = findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("email"));
// Callback registration
callbackManager = CallbackManager.Factory.create();
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "Facebook login token: " + loginResult.getAccessToken().getToken());
}
@Override
public void onCancel() {
Log.d(TAG, "Facebook login canceled.");
}
@Override
public void onError(FacebookException error) {
Log.d(TAG, "Facebook login error: " + error.getMessage());
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (callbackManager != null) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
super.onActivityResult(requestCode, resultCode, data);
}
}
@@ -6,10 +6,10 @@
android:layout_height="match_parent"
tools:context="dragosholban.com.bestphotos.MainActivity">
<TextView
<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"

0 comments on commit 0357dd7

Please sign in to comment.