I have been struggling with this for a few hours. Here's the steps I take:
Create a new bare bones Codename One app with main package
com.recipes.authand main classFacebookAuthCreate facebook app for android, setting package name to
com.recipes.authand setting the main class name toFacebookAuthSubThen, generate hash and paste it. The hash is created using:
keytool -exportcert -alias (your_keystore_alias) -keystore (path_to_your_keystore) | openssl sha1 -binary | openssl base64
Add build hint in Codename One facebook.appId
Write the following code in the main form:
String clientId = "xxxxx"; String redirectURI = "{server}/auth/facebook"; String clientSecret = "xxx"; Login fb = FacebookConnect.getInstance(); fb.setClientId(clientId); fb.setRedirectURI(redirectURI); fb.setClientSecret(clientSecret); //Sets a LoginCallback listener fb.setCallback(new LoginCallback() { @Override public void loginSuccessful() { ConnectionRequest connectionRequest = new ConnectionRequest(); connectionRequest.setPost(false); connectionRequest.setUrl( "{server}/auth/facebook/callback?access_token=" + fb.getAccessToken().getToken()); connectionRequest.addResponseListener(event -> { Log.p(new String(connectionRequest.getResponseData())); }); NetworkManager.getInstance().addToQueue(connectionRequest); } @Override public void loginFailed(String errorMessage) { Dialog.show("No!", "it did not work!", "sad", null); } }); Form hi = new Form("Hi World"); Button loginWithFacebook = new Button("Fb Auth"); loginWithFacebook.addActionListener(event -> { //trigger the login if not already logged in if(!fb.isUserLoggedIn()){ fb.doLogin(); }else{ //get the token and now you can query the facebook API String token = fb.getAccessToken().getToken(); } }); hi.add(loginWithFacebook); hi.show();where {server} is my server's uri. The auth path of my server is
{server}/auth/facebook, and the callback URL is{server}/auth/facebook/callbackand the success redirect is{server}/api/Users/me.Add web client to the Facebook app, to enable the simulator
On facebook app page in products, add product, and then add Facebook Login with my server entered in Valid OAuth redirect URIs.
Now when I try from the device, I get an error about invalid hash.
In one of these answers, it is suggested that this could be because
Android Key hash will change if you build apk from another device(PC)
Which in fact is correct since I am using Codename One cloud builds. I followed the following guides: Facebook Login - Codename One, Social Chat Part 3 - Codename One and could not find an answer. But how to setup everything related to Facebook authentication with my own server? I am looking for a simple, step by step approach that actually works.