How get the information though Facebook Integration
//Gradle File
implementation'com.facebook.android:facebook-android-sdk:4.20.0'
//Declare In Manifest file
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
//End
//OnCreate
callbackManager=CallbackManager.Factory.create();
//End
//Use this in click event and getting the information. LoginManager.getInstance().logInWithReadPermissions(LoginActivity.this,Arrays.asList("public_profile","email"));
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>(){
@Override
public void onSuccess(final LoginResult loginResult){
Toast.makeText(LoginActivity.this,"Please wait",Toast.LENGTH_SHORT).show();
Log.d(">>","User ID: "+
loginResult.getAccessToken().getUserId());
GraphRequest request=GraphRequest.newMeRequest(loginResult.getAccessToken(),new GraphRequest.GraphJSONObjectCallback(){
@Override
public void onCompleted(JSONObject object,GraphResponse response){
try{
facebookEmail=object.getString("email");
name=object.getString("name");
Log.i(">>facebookLoginResults",object.getString("email")+object.getString("name")+
loginResult.getAccessToken().getUserId());
}catch(Exception e){
Log.i(">>facebookLogin","onCompleted: "+e.getMessage());
}
}
});
Bundle parameters=new Bundle();
parameters.putString("fields","email,name");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel(){
Toast.makeText(LoginActivity.this,"Login Cancel",Toast.LENGTH_SHORT).show();
Log.i(">>facebookLogin","cancel: "+"");
}
@Override
public void onError(FacebookException exception){
Toast.makeText(LoginActivity.this,"Login Error",Toast.LENGTH_SHORT).show();
Log.i(">>facebookLogin","error: ");
}
});
.build();
//End
No comments:
Post a Comment