我有两个EditText(id,密码)和一个按钮(登录)。 当我点击按钮时,我想登录FaceBook并打开网站。 但我无法观看已登录的网站。
这是我的代码。
public class MainActivity extends Activity {
EditText id;
EditText password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
id = (EditText) findViewById(R.id.editText1);
password = (EditText) findViewById(R.id.editText2);
Button logIn = (Button) findViewById(R.id.button1);
logIn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Login();
}
});
}
public void Login (){
System.out.println("id:" + id.getText().toString());
System.out.println("password:" + password.getText().toString());
try {
Connection.Response res = Jsoup.connect("https://www.facebook.com/login.php?login_attempt=1")
.data("email", id.getText().toString())
.data("pass", password.getText().toString())
.method(Method.POST)
.timeout(60000)//1 min
.execute();
Map<String, String> loginCookies = res.cookies();
Document doc = Jsoup.connect("https://www.facebook.com")
.cookies(loginCookies)
.get();
System.out.println(doc.text().toString());
} catch (Exception e) {
e.printStackTrace();
}
Uri uri = Uri.parse("https://www.facebook.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
}