开发者

Java - Logging Into Facebook

I have a URL that I need to go to in my Java application and then get the source code of the page. The problem is that you need to be authorized on Facebook to access the page.

Is 开发者_如何学JAVAit possible to go into a web browser, log-in to Facebook then somehow run my application and have access to the page?

Or do I need to log into Facebook through my application? How do I do that? I have tried using this: code.google.com/p/facebook-java-api/ but I can't find any basic tutorials for noobs on how to set this up and most are outdated so please don't link me to anything.

I'd prefer to use only the official API if that's possible...

Thanks in advance.


The following code and this page should help you to log into your facebook with Java:

final WebClient webClient = new WebClient(); 
final HtmlPage page1 = webClient.getPage("http://www.facebook.com"); 
final HtmlForm form = page1.getFormByName("login_form");  
final HtmlSubmitInput button = form.getInputsByValue("Log in"); 
final HtmlTextInput textField = form.getInputByName("email");
textField.setValueAttribute("youremailaddress@domain.com"); 
final HtmlTextInput textField = form.getInputByName("pass");      
textField.setValueAttribute("yourPassword"); 
final HtmlPage page2 = button.click(); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜