dsebastien / greader-unofficial

Automatically exported from code.google.com/p/greader-unofficial
GNU Lesser General Public License v3.0
0 stars 0 forks source link

GoogleReaderException on GoogleReader.getLabels() #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create new GoogleReader objet with correct username/password
2. Call reader.login() and get true
3. Call reader.getLabels()

GoogleReader reader = new GoogleReader("username", "password");
if (reader.login()) {
  for (Label label : reader.getLabels()) {
    System.out.println(label.getName());
  }
}                

What is the expected output? What do you see instead?
The labels names

I get this exception:

Exception in thread "main"
be.lechtitseb.google.reader.api.model.exception.GoogleReaderException:
Problem while manipulating the JSON content
    at
be.lechtitseb.google.reader.api.util.GoogleReaderUtil.getLabelsFromJSON(GoogleRe
aderUtil.java:394)
    at
be.lechtitseb.google.reader.api.core.GoogleReader.getLabels(GoogleReader.java:15
3)
    at
be.lechtitseb.google.reader.api.core.GoogleReaderTest.main(GoogleReaderTest.java
:18)
Caused by: org.json.JSONException: JSONObject["shared"] not found.
    at org.json.JSONObject.get(JSONObject.java:422)
    at org.json.JSONObject.getString(JSONObject.java:593)
    at
be.lechtitseb.google.reader.api.util.GoogleReaderUtil.getLabelsFromJSON(GoogleRe
aderUtil.java:367)
    ... 2 more

I have fixed this by removing all references to shared variable in
getLabelsFromJSON method on GoogleReaderUtil:

public static List<Label> getLabelsFromJSON(String content) throws
GoogleReaderException {
  LOG.trace("Getting labels from JSON");
  List<Label> returnValue = new ArrayList<Label>();
  if (content == null) {
    return returnValue;
  }
  try {
    JSONObject json = new JSONObject(content);
    // System.out.println(json.toString(3));
    if (!json.isNull("tags")) {
      JSONArray labels = json.getJSONArray("tags");
      Label tmp = null;
      String id = null;
      // String shared = null;
      for (int i = 0; i < labels.length(); i++) {
        tmp = new Label();
        id = labels.getJSONObject(i).getString("id");   
        //shared = labels.getJSONObject(i).getString("shared");
        tmp.setId(id);
        if (id.indexOf(Constants.ITEM_STATE) >= 0) {
          // FIXME maybe these should be treated differently
          // (state object?)
          tmp.setName(id.substring(id.indexOf(Constants.ITEM_STATE)
                      + Constants.ITEM_STATE.length() + 1));
        } else if (id.indexOf("/label/") > 0) {
          tmp.setName(id.substring(id.indexOf("/label/")
                      + "/label/".length()));
        } else {
          LOG.warn("Unknown label type: " + id);
        }
        //if ("all".equals(shared)) {
          // FIXME shared could be something else I think, like
          // one/multiple friend(s), so this should be modified
          //tmp.setShared(true);
        //}
        returnValue.add(tmp);
      }
    }
    return returnValue;
  } catch (JSONException e) {
      throw new GoogleReaderException("Problem while manipulating the JSON
content", e);
  }
}

I don't know how to implement a better solution, but I hope this
description be useful

Original issue reported on code.google.com by ffbelt...@gmail.com on 26 Mar 2010 at 4:37

GoogleCodeExporter commented 9 years ago

Original comment by attila.b...@gmail.com on 27 Oct 2011 at 9:50