Google+ API ItemScope getRatingValue返回null字符串

时间:2013-12-14 17:25:25

标签: android google-api google-plus

在使用Google+ API的Android应用中,我可以使用以下代码编写“ReviewActivity”类型的片刻:

ItemScope rating = new ItemScope.Builder()
            .setType("http://schema.org/Rating")
            .setRatingValue(Float.toString(oeuvre.getRating()))
            .setBestRating("5").setWorstRating("0").build();
ItemScope result = new ItemScope.Builder()
            .setType("http://schema.org/Review").setName(titre)
            .setUrl(urlfreebase)
            .setDescription(oeuvre.getNomPeintre()).setReviewRating(rating)
            .build();
ItemScope target = new ItemScope.Builder().setUrl(urlfreebase).build();
Moment moment = new Moment.Builder()
            .setType("http://schemas.google.com/ReviewActivity")
            .setTarget(target).setResult(result).build();
if (monPlusClient.isConnected()) {
    monPlusClient.writeMoment(moment);
}

它的作品,我可以使用我的桌面在我的Google+个人资料中阅读它们。

当我加载片刻时,在我的应用开始时,我也能够阅读我的片刻,但我无法获得用户选择的评分值。

在我的听众中:

public void onMomentsLoaded(ConnectionResult status,
        MomentBuffer momentBuffer, String nextPageToken, String updated) {
...
}

我收到了这个目标:

{"description":"Pablo Picasso","url":"https:\/\/developers.google.com\/+\/web\/snippet\/examples\/review","id":"https:\/\/developers.google.com\/+\/web\/snippet\/examples\/review","reviewRating":{"ratingValue":"4.0","worstRating":"0","bestRating":"5"},"name":"Le Pigeon aux petits pois"}

如您所见,评级已正确设置:

"reviewRating":{"ratingValue":"4.0","worstRating":"0","bestRating":"5"}

但是当我尝试通过API阅读它时:

ItemScope res = m.getResult();
String titre = res.getName();
String desc = res.getDescription();
String streval = res.getRatingValue();

String streval始终为null

1 个答案:

答案 0 :(得分:0)

我通过使用JSON字符串解决了这个问题:

ItemScope res = m.getResult();
String titre = res.getName();
String desc = res.getDescription();
try {
    JSONObject jres = new JSONObject(res.toString());
    JSONObject jeval = jres.getJSONObject("reviewRating");
    String streval = jeval.getString("ratingValue");
} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}