trying to login user with facebook in my MainActivity, and Android Studio won’t understand the command.
in the line “Backendless.UserService.loginWithFacebook(MainActivity.this, facebookFieldMappings, permissions, new AsyncCallback<BackendlessUser>()” and so on, it show the error red underline, as you can see in the screenshot.
what did I do wrong ?
thanks, Gil.
Hi, Gil.
As you can see in loginWithFacebook method signature (left click on method name with Ctrl pressed):
public void loginWithFacebook(Activity context, WebView webView, Map<String, String> facebookFieldsMappings, List<String> permissions, AsyncCallback<BackendlessUser> responder)
it takes WebView as a second parameter. In your case, you can use “null” instead of webView.
Thanks, I can compile now, but then I try to get the user’s mail and first_name from facebook, nothing happens.
This is my code, to my understanding it should work… :
The problem is with the connection to facebook.
even though I inserted the facebook app ID and facebook app secret, when I run my app it says =
“Given URL is not permitter by the Application configuretion: One or more of the gibel URLs is not permitted by the App’s settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the Apps domains”
If you do not set Facebook App ID and App Secret then these credentials will be used from our default app on Facebook. You can try it out (without Facebook credentials), just to see how it should be working.
If you provide credentials of your own Facebook application, than you are responsible for its correct settings. You can contact Facebook documentation https://developers.facebook.com/docs/android/getting-started on that.
As it looks to me, you should provide correct URL settings in your Facebook app - navigate your Facebook app settings and check “App Domains”, “Site URL” (you’ll have to choose “Add platform | Web Site” first) and “Valid OAuth redirect URIs” (on “Advanced” tab), they should say “https://api.backendless.com/”
I’ve removed m own app ID and secret (left it blank), and inserted the https://api.backendless.com/ as a website and in the Valid OAuth redirect URIs in the advanced tab.
now my app says “could not approve social account.” any ideas ?
Gil, you can use the CodeGeneration sample for Facebook login. In Backendless Console navigate to tab “Codegeneration” / “Android”. In IDE dropdown you can choose “Intellij Idea”, check Facebook Login and press Download Project button below. You can use these java classes a Facebook Login sample.
Thanks Anatolii but I can’t seem to open it right with Android Studio. it only shows the java classes and not the layouts, res etc.
anyways it’s similar to my own code. which seems to work fine except for the fact the it the Backendless website I see a long number where the user’s mail should be, and I get no detail about the user from facebook : first_name, etc.
CodeGeneration feature for Android Studio will be released shortly.
Right now you can you the project I’ve attached (be sure to replace APPLICATION_ID and SECRET_KEY in file Defaults.java)
Did you try to put breakpoint into hadleResponse method of the callback you pass to loginWithFacebook method?
Like this:
public void onLoginWithFacebookButtonClicked()
{
Backendless.UserService.loginWithFacebook( LoginActivity.this, new SocialCallback<BackendlessUser>( LoginActivity.this )
{ @Override
public void handleResponse( BackendlessUser backendlessUser )
{
// PUT BREAKPOINT HERE and check the backendlessUser entity you receive
startActivity( new Intent( getBaseContext(), LoginSuccessActivity.class ) );
finish();
}
} );
}
Backendless.UserService.loginWithFacebook(MainActivity.this, null, facebookFieldMappings, permissions, new AsyncCallback<BackendlessUser>()
{ @Override
public void handleResponse( BackendlessUser backendlessUser )
{
// user logged in successfully
Intent intent = new Intent( MainActivity.this, FeedActivity.class );
startActivity( intent ); // go to the user feed activity in my app
}
@Override
public void handleFault( BackendlessFault backendlessFault )
{
// failed to log in
}
The case that you descibed (getting id number in email field) is valid if you do not add “email” permission.
Adding these two factors it looks to me that the code you provided is not the code that you actually run(looks like you run the loginWithFacebook(Activity context, AsyncCallback<BackendlessUser> responder) method, without permissions and fieldsMapping).
Please check that again
it took me 1 minute to fix the code, and 59 minutes to understand that I need to delete the “numbered” user and register again.
works perfectly. I thank you!
And is it possible to create a push notification when the user changes an attribute like “current city” to all his followers?
For this case you can use business logic. More information you can get from this documentation: https://backendless.com/documentation/business-logic/java/bl_overview.htm
Regards,
Kate.