本文整理汇总了Java中com.restfb.json.JsonObject.getJsonObject方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.getJsonObject方法的具体用法?Java JsonObject.getJsonObject怎么用?Java JsonObject.getJsonObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.restfb.json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.getJsonObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFriends
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
/**
* Return list of friends based on list of given ids
*
* @param idsOfFriendsToDisplay of friends, which we want to obtain from facebook
* @return list of friends
*/
public List<FacebookUserBean> getFriends(final List<String> idsOfFriendsToDisplay) throws IOException, PortletException {
List<FacebookUserBean> fbFriends = new ArrayList<FacebookUserBean>();
// Render friends with their pictures
if (idsOfFriendsToDisplay.size() > 0) {
// Fetch all required friends with obtained ids
JsonObject friendsResult = this.fetchObjects(idsOfFriendsToDisplay, JsonObject.class,
Parameter.with("fields", "id,name,picture"));
if (friendsResult == null) {
return fbFriends;
}
for (String id : idsOfFriendsToDisplay) {
JsonObject current = friendsResult.getJsonObject(id);
UserWithPicture friend = facebookClient.getJsonMapper().toJavaObject(current.toString(), UserWithPicture.class);
fbFriends.add(new FacebookUserBean(friend));
}
}
return fbFriends;
}
示例2: findMaxMovieIndex
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
private static int findMaxMovieIndex(final JsonArray array, int start) {
double maxValue = 0;
int result = start;
for (int i = start; i < array.length(); ++i) {
final JsonObject current = array.getJsonObject(i);
final JsonObject values = current.getJsonObject("value");
double imdbRating = 0;
double friendRating = 0;
try {
friendRating = Double.parseDouble(values.getString("friendRating"));
imdbRating = Double.parseDouble(values.getString("rating"));
} catch (Exception e) {
}
final double rating = imdbRating + friendRating;
if (rating > maxValue) {
maxValue = rating;
result = i;
}
}
return result;
}
示例3: debugToken
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
/**
* @see com.restfb.FacebookClient#debugToken(java.lang.String)
*/
public DebugTokenInfo debugToken(String inputToken) {
verifyParameterPresence("inputToken", inputToken);
String response = makeRequest("/debug_token", Parameter.with("input_token", inputToken));
JsonObject json = new JsonObject(response);
JsonObject data = json.getJsonObject("data");
try {
return getJsonMapper().toJavaObject(data.toString(), DebugTokenInfo.class);
} catch (Throwable t) {
throw new FacebookResponseContentException("Unable to parse JSON from response.", t);
}
}
示例4: throwFacebookResponseStatusExceptionIfNecessary
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
/**
* Throws an exception if Facebook returned an error response. Using the Graph API, it's possible to see both the new
* Graph API-style errors as well as Legacy API-style errors, so we have to handle both here. This method extracts
* relevant information from the error JSON and throws an exception which encapsulates it for end-user consumption.
* <p>
* For Graph API errors:
* <p>
* If the {@code error} JSON field is present, we've got a response status error for this API call.
* <p>
* For Legacy errors (e.g. FQL):
* <p>
* If the {@code error_code} JSON field is present, we've got a response status error for this API call.
*
* @param json
* The JSON returned by Facebook in response to an API call.
* @param httpStatusCode
* The HTTP status code returned by the server, e.g. 500.
* @throws FacebookGraphException
* If the JSON contains a Graph API error response.
* @throws FacebookResponseStatusException
* If the JSON contains an Legacy API error response.
* @throws FacebookJsonMappingException
* If an error occurs while processing the JSON.
*/
protected void throwFacebookResponseStatusExceptionIfNecessary(String json, Integer httpStatusCode) {
// If we have a legacy exception, throw it.
throwLegacyFacebookResponseStatusExceptionIfNecessary(json, httpStatusCode);
// If we have a batch API exception, throw it.
throwBatchFacebookResponseStatusExceptionIfNecessary(json, httpStatusCode);
try {
// If the result is not an object, bail immediately.
if (!json.startsWith("{"))
return;
JsonObject errorObject = new JsonObject(json);
if (errorObject == null || !errorObject.has(ERROR_ATTRIBUTE_NAME))
return;
JsonObject innerErrorObject = errorObject.getJsonObject(ERROR_ATTRIBUTE_NAME);
// If there's an Integer error code, pluck it out.
Integer errorCode =
innerErrorObject.has(ERROR_CODE_ATTRIBUTE_NAME) ? toInteger(innerErrorObject
.getString(ERROR_CODE_ATTRIBUTE_NAME)) : null;
Integer errorSubcode =
innerErrorObject.has(ERROR_SUBCODE_ATTRIBUTE_NAME) ? toInteger(innerErrorObject
.getString(ERROR_SUBCODE_ATTRIBUTE_NAME)) : null;
throw graphFacebookExceptionMapper
.exceptionForTypeAndMessage(errorCode, errorSubcode, httpStatusCode,
innerErrorObject.getString(ERROR_TYPE_ATTRIBUTE_NAME),
innerErrorObject.getString(ERROR_MESSAGE_ATTRIBUTE_NAME));
} catch (JsonException e) {
throw new FacebookJsonMappingException("Unable to process the Facebook API response", e);
}
}