本文整理汇总了Java中com.restfb.exception.FacebookOAuthException类的典型用法代码示例。如果您正苦于以下问题:Java FacebookOAuthException类的具体用法?Java FacebookOAuthException怎么用?Java FacebookOAuthException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FacebookOAuthException类属于com.restfb.exception包,在下文中一共展示了FacebookOAuthException类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: oauthExceptionWithErrorSubcode
import com.restfb.exception.FacebookOAuthException; //导入依赖的package包/类
/**
* 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());
}
}
示例2: fetchObject
import com.restfb.exception.FacebookOAuthException; //导入依赖的package包/类
public static <T> T fetchObject(FacebookClient fbClient, String name, Class<T> objClass,
Parameter... parameters) {
try {
return fbClient.fetchObject(name, objClass, parameters);
} catch(FacebookException e) {
if (e instanceof FacebookOAuthException) {
throw ErrorResponseMsg.createException(e.getMessage(), ErrorInfo.Type.AUTHENTICATION);
}
if (e.getMessage().toLowerCase().contains("unsupported get request")) {
// This seems to be thrown when there is a permissions issue.
// http://stackoverflow.com/questions/6843796/graph-api-returns-false-or-unsupported-get-request-accessing-public-facebook
throw ErrorResponseMsg.createException(
"Access to faceboook object '" + name + "' is restricted",
ErrorInfo.Type.PARTNER_SERVICE_FAILURE);
}
throw ErrorResponseMsg.createException(e, ErrorInfo.Type.PARTNER_SERVICE_FAILURE);
}
}
示例3: setUp
import com.restfb.exception.FacebookOAuthException; //导入依赖的package包/类
@Before
public void setUp() {
this.callbackHandler = mock(CallbackHandler.class);
this.facebookClient = mock(FacebookClient.class);
this.facebookOAuthException = mock(FacebookOAuthException.class);
this.jsonMapper = mock(JsonMapper.class);
this.messenger = new DefaultMessenger(verifyToken, appSecret, callbackHandler, facebookClient);
when(facebookClient.getJsonMapper()).thenReturn(jsonMapper);
}
示例4: oauthExceptionWithErrorCode
import com.restfb.exception.FacebookOAuthException; //导入依赖的package包/类
/**
* Do we correctly handle the case where FB returns an OAuthException with an error code?
*/
@Test
public void oauthExceptionWithErrorCode() {
FacebookClient facebookClient =
facebookClientWithResponse(new Response(403,
"{\"error\":{\"message\":\"(#210) User not visible\",\"type\":\"OAuthException\",\"code\":210}}"));
try {
facebookClient.fetchObject("me", User.class);
} catch (FacebookOAuthException e) {
assertEquals("(#210) User not visible", e.getErrorMessage());
assertEquals("OAuthException", e.getErrorType());
assertEquals(Integer.valueOf(210), e.getErrorCode());
}
}
示例5: oauthExceptionWithoutErrorCode
import com.restfb.exception.FacebookOAuthException; //导入依赖的package包/类
/**
* 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());
}
}
示例6: exceptionForTypeAndMessage
import com.restfb.exception.FacebookOAuthException; //导入依赖的package包/类
/**
* @see com.restfb.exception.FacebookExceptionMapper#exceptionForTypeAndMessage(java.lang.Integer,
* java.lang.Integer, java.lang.String, java.lang.String)
*/
public FacebookException exceptionForTypeAndMessage(Integer errorCode, Integer errorSubcode,
Integer httpStatusCode, String type, String message) {
if ("OAuthException".equals(type) || "OAuthAccessTokenException".equals(type))
return new FacebookOAuthException(type, message, errorCode, errorSubcode, httpStatusCode);
if ("QueryParseException".equals(type))
return new FacebookQueryParseException(type, message, errorCode, errorSubcode, httpStatusCode);
// Don't recognize this exception type? Just go with the standard
// FacebookGraphException.
return new FacebookGraphException(type, message, errorCode, errorSubcode, httpStatusCode);
}
示例7: exceptionForTypeAndMessage
import com.restfb.exception.FacebookOAuthException; //导入依赖的package包/类
/**
* @see com.restfb.exception.FacebookExceptionMapper#exceptionForTypeAndMessage(java.lang.Integer,
* java.lang.Integer, java.lang.String, java.lang.String)
*/
@Override
public FacebookException exceptionForTypeAndMessage(Integer errorCode, Integer errorSubcode,
Integer httpStatusCode, String type, String message) {
if (errorCode == API_EC_PARAM_ACCESS_TOKEN)
return new FacebookOAuthException(String.valueOf(errorCode), message, errorCode, errorSubcode, httpStatusCode);
// Don't recognize this exception type? Just go with the standard
// FacebookResponseStatusException.
return new FacebookResponseStatusException(errorCode, message);
}
示例8: isValidated
import com.restfb.exception.FacebookOAuthException; //导入依赖的package包/类
public static boolean isValidated(String accessToken, String userID) {
try {
FacebookClient fc = new DefaultFacebookClient(accessToken, Version.VERSION_2_4);
String id = fc.fetchObject("me", User.class).getId();
if (!id.equals(userID)) {
return false;
}
return true;
} catch (FacebookOAuthException e) {
e.printStackTrace();
return false;
}
}
示例9: isValidatedFacebookClient
import com.restfb.exception.FacebookOAuthException; //导入依赖的package包/类
public static FacebookClient isValidatedFacebookClient(String accessToken, String userID) {
try {
FacebookClient fc = new DefaultFacebookClient(accessToken, Version.VERSION_2_4);
String id = fc.fetchObject("me", User.class).getId();
if (!id.equals(userID)) {
return null;
}
return fc;
} catch (FacebookOAuthException e) {
e.printStackTrace();
return null;
}
}