我需要使用Java登錄來獲取我的user_accessToken。我有使用FacebookOAuthResult嗎?如果是,如何? 我寫了一個Applet登錄到Facebook。它有效,但我無法獲得令牌。用Java登錄Facebook獲取用戶accessToken
...
String GraphURL = "https://graph.facebook.com/me/friends?&access_token=" + token;
URL newURL = URL(GraphURL);
HttpsURLConnection https = (HttpsURLConnection)newURL.openConnection();
https.setRequestMethod("HEAD");
https.setUseCache(false);
...
//open a connection window like:
if(Desktop.isDesktopSupported())
{
Desktop.getDesktop().browse(new URI(GraphURL));
}
else if(...
這裏獲取令牌。這是正確的?
String getTokenUrl = "https://www.facebook.com/dialog/oauth?client_id=MY_APP_ID&redirect_uri=https%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&response_type=token&display=popup&scope=user_about_me%2Cread_stream%2C%20share_item";
Desktop desktop = Desktop.getDesktop();
desktop.browse(new URL(getTokenUrl).toURI());
URL tokenURL = new URL(getTokenUrl);
URLConnection connect = tokenURL.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream()));
String inputLine;
StringBuffer bufferr = new StringBuffer();
while ((inputLine = in.readLine()) != null)
bufferr.append(inputLine + "\n");
in.close();
token = bufferr.toString();
HttpURLConnection myWebClient = (HttpURLConnection)url.openConnection();
myWebClient.setRequestMethod("HEAD");
myWebClient.setUseCaches(false);
//webClient..
try
{
String gAntwort = myWebClient.getResponseMessage();
if (myWebClient.getResponseCode() != HttpURLConnection.HTTP_OK)
{
//Not OK
//JOptionPane.showMessageDialog(null, conn.getResponseMessage(), "URL Response", JOptionPane.INFORMATION_MESSAGE);
}
init();
} catch (Exception d){
}