Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add Facebook Login
- Loading branch information
1 parent
83b08b9
commit 0357dd7
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
app/src/main/java/dragosholban/com/bestphotos/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters