Пример #1
0
  /** Do we correctly handle the case where FB returns an OAuthException without an error code? */
  @Test
  public void oauthExceptionWithoutErrorCode() {
    FacebookClient facebookClient =
        facebookClientWithResponse(
            new Response(
                403,
                "{\"error\":{\"message\":\"(#210) User not visible\",\"type\":\"OAuthException\"}}"));

    try {
      facebookClient.fetchObject("me", User.class);
    } catch (FacebookOAuthException e) {
      assertEquals("(#210) User not visible", e.getErrorMessage());
      assertEquals("OAuthException", e.getErrorType());
      assertEquals(null, e.getErrorCode());
    }
  }
Пример #2
0
 /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
 @Override
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   // TODO Auto-generated method stub
   PrintWriter out = response.getWriter();
   out.println("* Fetching single objects *");
   try {
     User user = fbClient.fetchObject("me", User.class);
     Page page = fbClient.fetchObject("tradesbyjack", Page.class);
     out.println("User name: " + user.getName());
     out.println("User name: " + user.getId());
     out.println("User name: " + user.getGender());
     out.println("Page likes: " + page.getLikes());
   } catch (FacebookOAuthException fbexp) {
     out.println("Cannot find user info. " + fbexp.getErrorMessage());
   }
 }
Пример #3
0
  /**
   * Do we correctly handle the case where FB returns an OAuthException with an error code and
   * subcode?
   */
  @Test
  public void oauthExceptionWithErrorSubcode() {
    FacebookClient facebookClient =
        facebookClientWithResponse(
            new Response(
                403,
                "{\"error\":{\"message\":\"App Not Installed\",\"type\":\"OAuthException\",\"code\":190,\"error_subcode\":458}}"));

    try {
      facebookClient.fetchObject("me", User.class);
    } catch (FacebookOAuthException e) {
      assertEquals("App Not Installed", e.getErrorMessage());
      assertEquals("OAuthException", e.getErrorType());
      assertEquals(Integer.valueOf(190), e.getErrorCode());
      assertEquals(Integer.valueOf(458), e.getErrorSubcode());
    }
  }