shinjuo
shinjuo

Reputation: 21012

Google-Voice-java getSMS()

I am trying to use the google-voice-java API to read texts from a google voice account. I cannot find much documentation on using it other then the code.google.com page. I just need a little help on how to correctly use getSMS();

Upvotes: 2

Views: 1725

Answers (1)

General Waters
General Waters

Reputation: 1139

The google-voice-java API will simply return back raw HTML of your Google Voice data. Thus, you need to parse through the HTML returned by getSMS();, and do with the data as you see fit.

If you'd like to just see what the data returned looks like at a console window, do the following

Voice voice = new Voice(userName, password);
String sms = voice.getSMS();
System.out.println(sms);

Based on that, you can see what the HTML looks like and how to parse through it.

Edit: Probably worth noting that you need to include the additional dependency jars to your build path; that should be more explicitly clear on their GettingStarted!

Edit 2: Based on your comment below, there are the getUnreadSMS() and markAsRead(msgID), but the former appears to return read SMS messages along with the unread ones.

If you notice at the top of the response XML returned by the getSMS() method (and majority of the other API methods), there is JSON data in the <json> element, which seems to have all the necessary information you need (including a isRead variable to indicate if a SMS is marked read, or not).

Pull down a response from the getSMS() method and use this online JSON viewer to better inspect the data in the <json> element, so you have an idea of what's in there. When you paste in the JSON data into the online viewer, omit the leading <![CDATA and trailing ]> inside the <json> element.

I would just setup a JSON parser (maybe even use GSON) and create SMS model objects based on the JSON data, ignoring the HTML completely; for unread messages, you want JSON objects with the isRead field set to false, obviously. You could then use the id field to pass into the markAsRead(msgID) method, to mark them read (I just tested this method and it works).

Upvotes: 1

Related Questions