'Using RestFB along side a JavaFX WebView, how can I post to Facebook?
I've been trying a number of ways to achieve a way to post to Facebook from within my JavaFX application using a WebView to manage login.
I have read Facebook's documentation but continue to get lost with user_key, codes, access_code, tokens and what not.
What I have so far is this:
My WebView loads this URL.
public static String userLogin() {
String state = UUID.randomUUID().toString();
return String.format(AUTHORIZATION_URL, CLIENT_ID, REDIRECT_URI, state);
}
User logs in and authorises my Facebook application and I capture the response
System.out.println("Response: " + response);
if (response.contains("code=")) {
String[] finalCode = response.split("code=");
Facebook.CODE = finalCode[1];
System.out.println("Access Key:" + finalCode[1]);
}
}
My webview displays the following:
SECURITY WARNING: Please treat the URL above as you would your password and do not share it with anyone. See the Facebook Help Centre for more information.
I also see my code returned:
https://www.facebook.com/connect/login_success.html?code=AQA4w...
I then try to get my User Token, by directing my webView here:
public static String getUserToken() {
return String.format(ACCESS_TOKEN_URL, CLIENT_ID, REDIRECT_URI, CLIENT_SECRET, CODE);
}
At which point my webview displays the following:
{
"error": {
"message": "Missing authorization code",
"type": "OAuthException",
"code": 1,
"fbtrace_id": "D/0gXWRYkx4"
}
}
How can I solve this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|