从桌面用java登录Facebook删除权限框
在从桌面应用程序用facebook进行了大量登录搜索之后,我使用DJ Native swing浏览器进行了自我搜索 但我仍然有一个问题,我需要改变一些东西 我正在使用启用的浏览器Swing登录facebook。当我登录Facebook时,我得到一个权限框,它要求用户权限。但我不想展示那个盒子。是否可以在Facebook中授予自动权限 我只想删除此警告对话框,并想授予自动权限,那么我如何才能做到这一点从桌面用java登录Facebook删除权限框,java,facebook,swing,facebook-graph-api,Java,Facebook,Swing,Facebook Graph Api,在从桌面应用程序用facebook进行了大量登录搜索之后,我使用DJ Native swing浏览器进行了自我搜索 但我仍然有一个问题,我需要改变一些东西 我正在使用启用的浏览器Swing登录facebook。当我登录Facebook时,我得到一个权限框,它要求用户权限。但我不想展示那个盒子。是否可以在Facebook中授予自动权限 我只想删除此警告对话框,并想授予自动权限,那么我如何才能做到这一点 欢迎任何建议 我解决了这个问题,只需删除一些参数,比如我创建URL public static
欢迎任何建议 我解决了这个问题,只需删除一些参数,比如我创建URL
public static String firstRequest = "https://graph.facebook.com/oauth/authorize?"
+ "client_id="
+ API_KEY
+ "&redirect_uri=http://www.facebook.com/connect/login_success.html&"
+ "scope=email,offline_access";
我只想问一次:)
好吧,这里是同样的例子
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.SimpleWebBrowserExample;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserAdapter;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserNavigationEvent;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.StringReader;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;
/**
*
* @author kishan
*/
public class FacBookApiLogin extends javax.swing.JFrame {
public static String API_KEY = "*****************";
public static String SECRET = "********************";
public static String firstRequest = "https://graph.facebook.com/oauth/authorize?"
+ "client_id="
+ API_KEY
+ "&redirect_uri=http://www.facebook.com/connect/login_success.html&"
+ "scope=email,offline_access";
//
public static String secondRequest = "https://graph.facebook.com/oauth/access_token?"
+ "client_id="
+ API_KEY
+ "&redirect_uri=http://www.facebook.com/connect/login_success.html&"
+ "client_secret=" + SECRET + "&code=";
public static String access_token = "";
public static boolean firstRequestDone = false;
public static boolean secondRequestDone = false;
static FacBookApiLogin apiLogin;
static SimpleFrame browserExample;
/**
* Creates new form FacBookApiLogin
*/
public FacBookApiLogin() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
LoginFacebook = new javax.swing.JButton();
AutoLoginButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
LoginFacebook.setText("Login Facebook");
LoginFacebook.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
LoginFacebookActionPerformed(evt);
}
});
AutoLoginButton.setText("Auto Login");
AutoLoginButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AutoLoginButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(AutoLoginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(LoginFacebook)
.addContainerGap(109, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(0, 247, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(LoginFacebook)
.addComponent(AutoLoginButton)))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void LoginFacebookActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
NativeInterface.open();
final JFrame authFrame = new JFrame();
// Create the JWebBrowser and add the WebBrowserAdapter
JPanel webBrowserPanel = new JPanel(new BorderLayout());
final JWebBrowser webBrowser = new JWebBrowser();
webBrowser.navigate(firstRequest);
webBrowser.addWebBrowserListener(new WebBrowserAdapter() {
@Override
public void locationChanged(WebBrowserNavigationEvent e) {
super.locationChanged(e);
// Check if first request was not done
if (!firstRequestDone) {
// Check if you left the location and were redirected to the next
// location
if (e.getNewResourceLocation().contains("http://www.facebook.com/connect/login_success.html?code=")) {
// If it successfully redirects you, get the verification code
// and go for a second request
String[] splits = e.getNewResourceLocation().split("=");
String stage2temp = secondRequest + splits[1];
System.err.println("URL location" + stage2temp);
webBrowser.navigate(stage2temp);
System.out.println("This is what we looking for" + splits[2]);
firstRequestDone = true;
if (firstRequestDone == true) {
//apiLogin.dispose();
//browserExample = new SimpleFrame();
//browserExample.setVisible(true);
}
}
} else {
// If secondRequest is not done yet, you perform this and get the
// access_token
if (!secondRequestDone) {
System.out.println(webBrowser.getHTMLContent());
// Create reader with the html content
StringReader readerSTR = new StringReader(webBrowser.getHTMLContent());
// Create a callback for html parser
HTMLEditorKit.ParserCallback callback
= new HTMLEditorKit.ParserCallback() {
public void handleText(char[] data, int pos) {
System.out.println(data);
// because there is only one line with the access_token
// in the html content you can parse it.
String string = new String(data);
System.out.println("Main string : " + data.toString());
String[] temp1 = string.split("&");
String[] temp2 = temp1[0].split("=");
access_token = temp2[1];
System.out.println("accesstoken is here" + access_token);
System.out.println("length of token" + temp2.length);
System.err.println("Temp 0" + temp2[0]);
}
};
try {
// Call the parse method
new ParserDelegator().parse(readerSTR, callback, false);
} catch (IOException e1) {
e1.printStackTrace();
}
// After everything is done, you can dispose the jframe
authFrame.dispose();
}
}
}
});
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
authFrame.add(webBrowserPanel);
authFrame.setSize(400, 500);
authFrame.setVisible(true);
}
private void AutoLoginButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
NativeInterface.open();
final JFrame loginFrame = new JFrame();
JPanel webBrowserPanel = new JPanel(new BorderLayout());
// this is the JWebBrowser i mentioned earlier
final JWebBrowser webBrowser = new JWebBrowser();
// You can set this fields to false, or even let them activated
webBrowser.setMenuBarVisible(false);
webBrowser.setButtonBarVisible(false);
webBrowser.setLocationBarVisible(false);
final String fb_url = "http://www.facebook.com/";
webBrowser.navigate(fb_url);
// Here we add to our JWebBrowser an Adapter and override the
// locationChanging() method. Here we can check, if we are
// changing the location
// in our case the String fb_url, then this JWebBrowser can be
// disposed.
// The Timer is set for 2 seconds, so we can still see if the
// login was successfull or not.
webBrowser.addWebBrowserListener(new WebBrowserAdapter() {
@Override
public void locationChanging(WebBrowserNavigationEvent e) {
super.locationChanging(e);
System.out.println(e.getNewResourceLocation());
if (!e.getNewResourceLocation().equals(fb_url)) {
Timer timer = new Timer(2000, new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
loginFrame.dispose();
}
});
timer.start();
}
}
});
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
loginFrame.add(webBrowserPanel);
loginFrame.setSize(400, 500);
loginFrame.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FacBookApiLogin.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FacBookApiLogin.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FacBookApiLogin.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FacBookApiLogin.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
apiLogin = new FacBookApiLogin();
apiLogin.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton AutoLoginButton;
private javax.swing.JButton LoginFacebook;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
/*
*要更改此许可证标题,请在“项目属性”中选择“许可证标题”。
*要更改此模板文件,请选择工具|模板
*然后在编辑器中打开模板。
*/
包com.SimpleWebBrowserExample;
导入chrris.dj.nativeswing.swtimpl.NativeInterface;
导入chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
导入chrris.dj.nativeswing.swtimpl.components.WebBrowserAdapter;
导入chrriis.dj.nativeswing.swtimpl.components.WebBrowserNavigationEvent;
导入java.awt.BorderLayout;
导入java.awt.event.ActionEvent;
导入java.awt.event.ActionListener;
导入java.io.IOException;
导入java.io.StringReader;
导入javax.swing.JFrame;
导入javax.swing.JPanel;
导入javax.swing.Timer;
导入javax.swing.text.html.HTMLEditorKit;
导入javax.swing.text.html.parser.ParserDelegator;
/**
*
*@作者基山
*/
公共类FacBookApiLogin扩展了javax.swing.JFrame{
公共静态字符串API_KEY=“*******************”;
公共静态字符串SECRET=“**********************”;
公共静态字符串firstRequest=”https://graph.facebook.com/oauth/authorize?"
+“客户端id=”
+API_密钥
+“&重定向\u uri”=http://www.facebook.com/connect/login_success.html&"
+“范围=电子邮件,脱机访问”;
//
公共静态字符串secondRequest=”https://graph.facebook.com/oauth/access_token?"
+“客户端id=”
+API_密钥
+“&重定向\u uri”=http://www.facebook.com/connect/login_success.html&"
+“客户_secret=“+secret+”&code=“;
公共静态字符串访问_token=“”;
公共静态布尔值firstRequestDone=false;
公共静态布尔值secondRequestDone=false;
静态FacBookApiLogin;
静态SimpleFrame浏览器示例;
/**
*创建新表单FacBookApiLogin
*/
公共FacBookApiLogin(){
初始化组件();
}
/**
*从构造函数中调用此方法来初始化表单。
*警告:不要修改此代码。此方法的内容始终为
*由表单编辑器重新生成。
*/
@抑制警告(“未选中”)
//
私有组件(){
jPanel1=newjavax.swing.JPanel();
LoginFacebook=newjavax.swing.JButton();
AutoLoginButton=newjavax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
LoginFacebook.setText(“登录Facebook”);
LoginFacebook.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
LoginFacebookActionPerformed(evt);
}
});
AutoLoginButton.setText(“自动登录”);
AutoLoginButton.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
已执行的自动登录(evt);
}
});
javax.swing.GroupLayout jPanel1Layout=新的javax.swing.GroupLayout(jPanel1);
setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jpanellayout.createSequentialGroup()
.addContainerGap()
.addComponent(AutoLoginButton,javax.swing.GroupLayout.PREFERRED\u SIZE,124,javax.swing.GroupLayout.PREFERRED\u SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(LoginFacebook)
.addContainerGap(109,简称最大值))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,jPanel1Layout.createSequentialGroup()
.addGap(0,247,短.MAX_值)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(LoginFacebook)
.addComponent(自动登录按钮)))
);
javax.swing.GroupLayout=newjavax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(布局);
layout.setHorizontalGroup(
createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1,javax.swing.GroupLayout.DEFAULT\u SIZE,javax.swing.GroupLayout.DEFAULT\u SIZE,Short.MAX\u值)
.addContainerGap())
);
layout.setVerticalGroup(
createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1,javax.swing.GroupLayout.DEFAULT\u SIZE,javax.swing.GroupLayout.DEFAULT\u SIZE,Short.MAX\u值)
.addContainerGap())
);
包装();
}//
私有void LoginFaceb