使用restFB并播放框架2.0.2时获取FacebookNetworkException

时间:2012-07-26 10:26:34

标签: playframework restfb

我在尝试从Facebook获取用户名或关于我时遇到异常。 我已经设置了一个应用程序并且正确地获取了令牌。

我进入浏览器网址字段:

http://localhost:9000/?code=AQCoZN22V9BJbG4o9CMPq0vbw5LnLCuaSJ87XctcvSM4t6DoaZu-HGD_co_Y63gd-M9NHOaT1BBWVk_SrtF5YVYgDcZfXo_KBiV9SVmXflzzD4nx0VNr76LU0THrXnzL5D3EEqP6uyzzJAoEV_dZ8VEXwA7ObRXpEUQU_n2ERFvLy6gY0pJhxRoBWAsjUGUJ9U8#_=_

我的代码:

public class Application extends Controller {

    private static final String FACEBOOK_APP_URL = 
        "https://www.facebook.com/dialog/oauth?client_id=271131522987567&redirect_uri=http://localhost:9000/&scope=user_about_me";


  public static Result index(String code) {
       String userDetails = connectToFacebook(code);
       return ok(index.render("Your new application is ready!\n" + userDetails));
  }

  private static String connectToFacebook(String token){
      FacebookClient facebookClient = new DefaultFacebookClient(token);
      System.out.println("\nGetting user\n");
     User user = facebookClient.fetchObject("me", User.class);
     return user.getAbout();
  }

}

和路由文件:

# Home page
GET     /                           controllers.Application.index(code)

# Map static resources from the /public folder to the /assets URL path
GET     /assets/*file               controllers.Assets.at(path="/public", file)

浏览器中的异常(播放框架):

[FacebookNetworkException: A network error occurred while trying to communicate with Facebook: Facebook request failed (HTTP status code null)]

In D:\play-2.0.2\injustice\target\scala-2.9.1\src_managed\main\routes_routing.scala at line 32.

28

29// @LINE:6

30case controllers_Application_index0(params) => {

31   call(params.fromQuery[String]("code", None)) { (code) =>

32        invokeHandler(_root_.controllers.Application.index(code), HandlerDef(this, "controllers.Application", "index", Seq(classOf[String])))

33   }

34}

并在控制台中:

Getting user

[error] application -

! @6b6b0mehm - Internal server error, for request [GET /?code=AQCoZN22V9BJbG4o9C
MPq0vbw5LnLCuaSJ87XctcvSM4t6DoaZu-HGD_co_Y63gd-M9NHOaT1BBWVk_SrtF5YVYgDcZfXo_KBi
V9SVmXflzzD4nx0VNr76LU0THrXnzL5D3EEqP6uyzzJAoEV_dZ8VEXwA7ObRXpEUQU_n2ERFvLy6gY0p
JhxRoBWAsjUGUJ9U8] ->

play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[Facebo
okNetworkException: A network error occurred while trying to communicate with Fa
cebook: Facebook request failed (HTTP status code null)]]
        at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [
play_2.9.1.jar:2.0.2]
         at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [
play_2.9.1.jar:2.0.2]
         at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
        at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.
2]
        at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.
2]
         at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.j
ar:2.0.2]
Caused by: com.restfb.exception.FacebookNetworkException: A network error occurr
ed while trying to communicate with Facebook: Facebook request failed (HTTP stat
us code null)
        at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(Defaul
tFacebookClient.java:492) ~[restfb-1.6.9.jar:na]
        at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.ja
va:469) ~[restfb-1.6.9.jar:na]
        at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.ja
va:428) ~[restfb-1.6.9.jar:na]
        at com.restfb.DefaultFacebookClient.fetchObject(DefaultFacebookClient.ja
va:238) ~[restfb-1.6.9.jar:na]
        at controllers.Application.connectToFacebook(Application.java:26) ~[clas
ses/:na]
        at controllers.Application.index(Application.java:19) ~[classes/:na]
Caused by: java.net.ConnectException: Connection timed out: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.6.0_27]
        at java.net.PlainSocketImpl.doConnect(Unknown Source) ~[na:1.6.0_27]
        at java.net.PlainSocketImpl.connectToAddress(Unknown Source) ~[na:1.6.0_
27]
        at java.net.PlainSocketImpl.connect(Unknown Source) ~[na:1.6.0_27]
        at java.net.SocksSocketImpl.connect(Unknown Source) ~[na:1.6.0_27]
        at java.net.Socket.connect(Unknown Source) ~[na:1.6.0_27]

正如您所看到的,在打印“获取用户”字符串后发生错误。

请帮忙, 提前谢谢!

0 个答案:

没有答案