本文整理汇总了Java中com.restfb.json.JsonObject.getString方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.getString方法的具体用法?Java JsonObject.getString怎么用?Java JsonObject.getString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.restfb.json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.getString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onResponse
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
@Override
public boolean onResponse(String response)
{
JsonObject o = new JsonObject(response);
try
{
email = o.getString("email");
name = o.getString("name");
locale = o.getString("locale");
}
catch (Exception e) {
return false;
}
return true;
}
示例2: onResponse
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
@Override
public boolean onResponse(String response)
{
JsonObject o = new JsonObject(response);
name = "Live-Account";
email = "";
locale = "en_US";
try
{
email = o.getJsonObject("emails").getString("preferred");
name = o.getString("name");
locale = o.getString("locale");
}
catch (Exception e) {
return false;
}
return true;
}
示例3: onResponse
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
@Override
public boolean onResponse(String response) {
JsonObject o = new JsonObject(response);
try {
email = o.getString("email");
name = o.getString("name");
locale = o.getString("locale");
} catch (Exception e) {
return false;
}
return true;
}
示例4: fetchSources
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
/*******************************************
* Fetching sources
*/
@Override
public void fetchSources() {
FacebookClient facebookClient =
new DefaultFacebookClient(this.token, Version.VERSION_2_8);
JsonObject jsonSource = facebookClient.fetchObject(this.value, JsonObject.class,
Parameter.with("fields", "" +
"picture, " +
"id, " +
"name"));
String name = jsonSource.getString("name");
String imageURL = jsonSource.getJsonObject("picture")
.getJsonObject("data")
.getString("url");
Source source = new Source();
source.setType("facebook");
source.setKey(this.key);
source.setName(name);
source.setValue(this.value);
source.setUrlImage(imageURL);
if (this.sourceDao.isExisting(this.key)) {
this.sourceDao.update(source);
} else {
this.sourceDao.add(source);
}
}
示例5: parseSignedRequest
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
/**
* @see com.restfb.FacebookClient#parseSignedRequest(java.lang.String, java.lang.String, java.lang.Class)
*/
@Override
@SuppressWarnings("unchecked")
public <T> T parseSignedRequest(String signedRequest, String appSecret, Class<T> objectType) {
verifyParameterPresence("signedRequest", signedRequest);
verifyParameterPresence("appSecret", appSecret);
verifyParameterPresence("objectType", objectType);
String[] signedRequestTokens = signedRequest.split("[.]");
if (signedRequestTokens.length != 2)
throw new FacebookSignedRequestParsingException(format(
"Signed request '%s' is expected to be signature and payload strings separated by a '.'", signedRequest));
String encodedSignature = signedRequestTokens[0];
String urlDecodedSignature = urlDecodeSignedRequestToken(encodedSignature);
byte[] signature = decodeBase64(urlDecodedSignature);
String encodedPayload = signedRequestTokens[1];
String urlDecodedPayload = urlDecodeSignedRequestToken(encodedPayload);
String payload = StringUtils.toString(decodeBase64(urlDecodedPayload));
// Convert payload to a JsonObject so we can pull algorithm data out of it
JsonObject payloadObject = getJsonMapper().toJavaObject(payload, JsonObject.class);
if (!payloadObject.has("algorithm"))
throw new FacebookSignedRequestParsingException("Unable to detect algorithm used for signed request");
String algorithm = payloadObject.getString("algorithm");
if (!verifySignedRequest(appSecret, algorithm, encodedPayload, signature))
throw new FacebookSignedRequestVerificationException(
"Signed request verification failed. Are you sure the request was made for the app identified by the app secret you provided?");
// Marshal to the user's preferred type.
// If the user asked for a JsonObject, send back the one we already parsed.
return objectType.equals(JsonObject.class) ? (T) payloadObject : getJsonMapper().toJavaObject(payload, objectType);
}
示例6: fetchNouvelles
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
public void fetchNouvelles() {
FacebookClient facebookClient =
new DefaultFacebookClient(this.token, Version.VERSION_2_8);
JsonObject jsonNewsData =
facebookClient.fetchObject(this.value + "/posts",
JsonObject.class, Parameter.with("fields", "" +
"message, " +
"link, " +
"created_time, " +
"name, " +
"picture"));
JsonArray jsonNewsArray = jsonNewsData.getJsonArray("data");
for (int i = 0; i < jsonNewsArray.length(); i++) {
JsonObject jsonSingleNews = jsonNewsArray.getJsonObject(i);
String id = jsonSingleNews.getString("id");
String message = jsonSingleNews.optString("message");
String link = jsonSingleNews.optString("link");
String date = jsonSingleNews.optString("created_time");
String name = jsonSingleNews.optString("name");
if (name == null || name.isEmpty()) {
name = message.substring(0, Math.min(15, message.length()));
}
String picture = jsonSingleNews.optString("picture");
Nouvelle nouvelle = new Nouvelle();
nouvelle.setId(id);
nouvelle.setTitre(name);
nouvelle.setMessage(message);
nouvelle.setLink(link);
nouvelle.setDate(parseDate(date));
nouvelle.setUrlPicture(picture);
nouvelle.setId_source(this.key);
if (this.nouvelleDao.isExisting(id)) {
this.nouvelleDao.update(nouvelle);
} else {
this.nouvelleDao.add(nouvelle);
}
}
}
示例7: createUser
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
private User createUser(JsonObject fbu) {
User user = new User(fbu.getString("id"), fbu.getString("name"));
user.setToken(accessToken);
return user;
}
示例8: executeInsightQueriesByMetricByDate
import com.restfb.json.JsonObject; //导入方法依赖的package包/类
/**
* Queries Facebook via FQL for several Insights at different date points.
* <p>
* The output groups the result by metric and then by date, matching the input arguments. Map entries may be
* {@code null} if Facebook does not return corresponding data, e.g. when you query a metric which is not available at
* the chosen period. The inner {@code Map}'s {@code Object} value may be a strongly typed value for some metrics, but
* in other cases Facebook returns a {@code JsonObject}.
* <p>
* Sample output, assuming 2 metrics were queried for 5 dates:
*
* <pre>
* {page_active_users = {
* 2011-jan-01 = 7,
* 2011-jan-02 = 26,
* 2011-jan-03 = 15,
* 2011-jan-04 = 10,
* 2011-jan-05= 687},
* page_tab_views_login_top_unique = {
* 2011-jan-01 = {"photos":2,"app_4949752878":3,"wall":30},
* 2011-jan-02 = {"app_4949752878":1,"photos":1,"app_2373072738":2,"wall":23},
* 2011-jan-03 = {"app_4949752878":1,"wall":12},
* 2011-jan-04 = {"photos":1,"wall":11},
* 2011-jan-05 = {"app_494975287":2,"app_237307273":2,"photos":6,"wall":35,"info":6}}
* </pre>
*
* @param facebookClient
* The {@code FacebookClient} used to communicate with the Insights API.
* @param pageObjectId
* The required object_id to query.
* @param metrics
* A not null/empty set of metrics that will be queried for the given {@code period}.
* @param period
* The required time period over which to query.
* @param periodEndDates
* A non-null, non-empty {@code Set} in which each date should be normalized to be midnight in the PST
* timezone; see {@link #convertToMidnightInPacificTimeZone(Set)}.
* @return A {@code Map} of {@code Maps}: the outer keys will be all the metrics requested that were available at the
* period/times requested. The inner keys will be the {@code Set} of periodEndDates.
* @see #convertToMidnightInPacificTimeZone(Set)
* @see #executeInsightQueriesByDate(FacebookClient, String, Set, Period, Set)
*/
public static SortedMap<String, SortedMap<Date, Object>> executeInsightQueriesByMetricByDate(
FacebookClient facebookClient, String pageObjectId, Set<String> metrics, Period period, Set<Date> periodEndDates) {
SortedMap<String, SortedMap<Date, Object>> result = new TreeMap<String, SortedMap<Date, Object>>();
SortedMap<Date, JsonArray> raw =
executeInsightQueriesByDate(facebookClient, pageObjectId, metrics, period, periodEndDates);
if (!raw.isEmpty()) {
for (Date date : raw.keySet()) {
JsonArray resultByMetric = raw.get(date);
// [{"metric":"page_active_users","value":582},
// {"metric":"page_tab_views_login_top_unique","value":{"wall":12,"app_4949752878":1}}]
for (int resultIndex = 0; resultIndex < resultByMetric.length(); resultIndex++) {
JsonObject metricResult = resultByMetric.getJsonObject(resultIndex);
try {
String metricName = metricResult.getString("metric");
Object metricValue = metricResult.get("value");
// store into output collection
SortedMap<Date, Object> resultByDate = result.get(metricName);
if (resultByDate == null) {
resultByDate = new TreeMap<Date, Object>();
result.put(metricName, resultByDate);
}
if (resultByDate.put(date, metricValue) != null)
throw new IllegalStateException(format(
"MultiQuery response has two results for metricName: %s and date: %s", metricName, date));
} catch (JsonException e) {
throw new FacebookJsonMappingException(format("Could not decode result for %s: %s", metricResult,
e.getMessage()), e);
}
}
}
}
return result;
}