线程“main”中的异常com.restfb.exception.FacebookOAuthException:收到OAuthException类型的Facebook错误响应

时间:2013-08-13 11:29:56

标签: java facebook api facebook-javascript-sdk restfb

我正在使用restFB API运行一个简单的代码,在我创建令牌访问后,程序正在运行,从我的Facebook帐户中检索数据,但过了一段时间我得到了这条异常消息

Exception in thread "main" com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: Error validating access token: Session has expired at unix time 1376380800. The current unix time is 1376392638.
    at com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:766)
    at com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:688)
    at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:630)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:592)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:556)
    at com.restfb.DefaultFacebookClient.fetchObject(DefaultFacebookClient.java:244)
    at Example.main(Example.java:19)

我运行的产生上述异常的代码如下:

public static void main(String[] args) {
    FacebookClient facebookClient = new DefaultFacebookClient("Token_Access_Code");

    User user = facebookClient.fetchObject("me", User.class);
    Page page = facebookClient.fetchObject("cocacola", Page.class);

    System.out.println("User name: " + user.getName());
    System.out.println("Page likes: " + page.getLikes());

}

有没有人经历过这样的例外?

1 个答案:

答案 0 :(得分:0)

您需要重新生成访问令牌。我遇到了同样的错误,即使访问令牌应该按照FB文档持续60天。检查此链接:

<强> http://developers.facebook.com/docs/facebook-login/access-tokens/#extending