Android login and authenticate facebook user into a backendless application

I have done upto the code below and can succesfully authenticate and login Facebook user.
I have compile 'com.backendless:backendless:3.0.15.1 in my build gradle.
@Override
public void onSuccess(LoginResult loginResult) {
// mDialog.dismiss();
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.e("response: ", response + “”);
user = new User();
user.facebookID = object.optString(“id”);
user.name = object.optString(“name”);
user.email = object.optString(“email”);
user.gender = object.optString(“gender”);
user.locale = object.optString(“locale”);
Utils.setCurrentUser(user, LoginActivity.this);
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
Toast.makeText(LoginActivity.this, "Logged in as " + user.name, Toast.LENGTH_LONG).show();
}
}
);
Bundle parameters = new Bundle();
parameters.putString(“fields”, “id, name, email, gender, locale, birthday, picture.width(80).height(80)”);
request.setParameters(parameters);
request.executeAsync();
}

Hi, George.

Did you try our sample for login with Facebook SDK? https://github.com/Backendless/Android-SDK/tree/master/samples/UserService/FacebookSDKSamples

Hi Anatolii,

Between

public static final String SERVER_URL = "[url=http://tc.themidnightcoders.com:8888]http://tc.themidnightcoders.com:8888"[/url];;

and

public static final String SERVER_URL="[url=https://api.backendless.com]https://api.backendless.com"[/url];;

Which one should i use?

Are these relevant?

//SET YOUR GOOGLE PROJECT ID BEFORE LAUNCH
//ALSO YOU SHOULD SET GOOGLE API KEY IN BACKENDLESS CONSOLE
public static final String GOOGLE_PROJECT_ID = "615371842711";
public static final String DEFAULT_CHANNEL = "default";

https://api.backendless.com

//SET YOUR GOOGLE PROJECT ID BEFORE LAUNCH
//ALSO YOU SHOULD SET GOOGLE API KEY IN BACKENDLESS CONSOLE
public static final String GOOGLE_PROJECT_ID = "615371842711";
public static final String DEFAULT_CHANNEL = "default";

It is for Messaging Service. You can ignore it now.

Thanks Anatolii, at least am able to see the facebook user details in the server now.What does BackendlessPref do? I have a MainActivity as the launcher activity and a LoginActivity that the user will be redirected to only if they have not been previously logged in or have logged out. Can this be used in a similar fashion as Shared Preferences in the launcher activity’s onCreate method. I have tried this in the MainActivity onCreate but it ain’t working

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
Backendless.UserService.isValidLogin(new DefaultCallback<Boolean>(this) {
@Override
public void handleResponse(Boolean isValidLogin) {
if (isValidLogin && Backendless.UserService.CurrentUser() == null) {
String currentUserId = Backendless.UserService.loggedInUser();
if (!currentUserId.equals("")) {
Backendless.UserService.findById(currentUserId,
new DefaultCallback<BackendlessUser>(MainActivity.this, "Logging in...") {
@Override
public void handleResponse(BackendlessUser currentUser) {
super.handleResponse(currentUser);
Backendless.UserService.setCurrentUser(currentUser);
finish();
}
});
}
}
super.handleResponse(isValidLogin);
}
});
}
I was previously using this
if (Utils.getCurrentUser(this) == null) {
Intent loginIntent = new Intent(this, LoginActivity.class);
loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
loginIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(loginIntent);
finish();
}

Odhiambo,

BackendlessPref is a class we use internally and it is not intended for use outside of Backendless SDK.

Mark