Facebook からユーザーの名前または自分について取得しようとすると、例外が発生します。アプリケーションをセットアップし、トークンを適切に取得しています。
ブラウザの URL フィールドに次のように表示されます。
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]
ご覧のとおり、「Getting user」文字列を出力した後にエラーが発生します。
助けてください、事前に感謝します!