Retrieving infomation from twitter search api

3 views
Skip to first unread message

pipigu85

unread,
Nov 10, 2009, 9:10:09 PM11/10/09
to Twitter Development Talk
Hi, I am currently using the twitter search api to retrieve tweets but
some of the tweets returned are not fully formed. I followed the link
to the actual tweet itself and it seems that when it comes across
tweets with " " , it gets cut off

Example: Actual tweet: Just Voted " I am voting for something"
Result that i see: Just Voted

Is there anyway to retrieve the full tweet? I am using Eclipse, Java
to do. Thanks!

This is how i retrieve the search result:

XMLInputFactory inputFactory = XMLInputFactory.newInstance();
InputStream in = new URL("http://search.twitter.com/
search.atom?q=" + search + "&page=1&rpp=100").openStream();

XMLEventReader eventReader =
inputFactory.createXMLEventReader(in);
boolean inEntry = false;
Item currentItem = null;

while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();

System.out.println(event);
if (event.isStartElement()) {
StartElement startElement = event.asStartElement();
if (event.asStartElement().getName
().getLocalPart().equals("title")) {
event = eventReader.nextEvent();
String title = event.asCharacters().getData();
if (!inEntry) {
channel.setTitle(title);//false
} else {
currentItem.setTitle(title);//true
}

continue;
}

Andrew Badera

unread,
Nov 11, 2009, 12:05:02 AM11/11/09
to twitter-deve...@googlegroups.com
I've not seen this issue. Do you have a character encoding switch or
miss somewhere?

Also, doesn't asCharacters have some depth to it? Is there an overload
or property at play here?

"XMLEvent.asCharacters()

The asCharacters() method return a java.xml.stream.Characters object.
From this object you can obtain the characters themselves, as well as
see if the characters are CDATA, white space, or ignorable white
space."

∞ Andy Badera
+1 518-641-1280 Google Voice
∞ This email is: [ ] bloggable [x] ask first [ ] private
∞ Google me: http://www.google.com/search?q=andrew%20badera

pipigu85

unread,
Nov 11, 2009, 1:15:45 AM11/11/09
to Twitter Development Talk
I'm not sure. The code is basically what i put with it getting some
other data like the date, link. All seems fine except this ommitting
content problem.

Even when i change to event.toString() in place of asCharacters(), it
still ommits out the information so it should not be due to
asCharacters() right?

Sorry, I'm still very new to all these Java, hoping someone could help
enlighten me.

Andrew Badera

unread,
Nov 11, 2009, 11:37:41 AM11/11/09
to twitter-deve...@googlegroups.com
What does the RAW XML response look like?

Reduce variables. Examine your inputs.

∞ Andy Badera
+1 518-641-1280 Google Voice
∞ This email is: [ ] bloggable [x] ask first [ ] private
∞ Google me: http://www.google.com/search?q=andrew%20badera

pipigu85

unread,
Nov 11, 2009, 7:35:21 PM11/11/09
to Twitter Development Talk
the raw file is in atom format and looks like this:

<entry>

<id>tag:search.twitter.com,2005:5607828675</id>


<published>2009-11-11T02:43:13Z</published>


<link type="text/html" href="http://twitter.com/green_stormroqr/
statuses/5607828675" rel="alternate"/>


<title>just voted &quot;Selena Gomez&quot; on &quot;Who's your
favorite Disney star?&quot;! Vote now &#10148; http://bit.ly/o2wGh</title>


<content type="html">just voted &amp;quot;Selena Gomez&amp;quot; on
&amp;quot;Who&amp;apos;s your favorite &lt;b&gt;Disney&lt;/b&gt; star?
&amp;quot;! Vote now &#10148; &lt;a href=&quot;http://bit.ly/
o2wGh&quot;&gt;http://bit.ly/o2wGh&lt;/a&gt;</content>


<updated>2009-11-11T02:43:13Z</updated>


<link type="image/png" href="http://a3.twimg.com/profile_images/
467518411/061403-1wt_normal.jpg" rel="image"/>


<twitter:geo>
</twitter:geo>


<twitter:source>&lt;a href=&quot;http://lolquiz.com&quot;
rel=&quot;nofollow&quot;&gt;LOL quiz&lt;/a&gt;</twitter:source>


<twitter:lang>en</twitter:lang>


<author>

<name>green_stormroqr (stormie verrett)</name>
<uri>http://twitter.com/green_stormroqr</uri>

</author>

</entry>



On Nov 12, 12:37 am, Andrew Badera <and...@badera.us> wrote:
> What does the RAW XML response look like?
>
> Reduce variables. Examine your inputs.
>
> ∞ Andy Badera
> ∞              +1 518-641-1280        +1 518-641-1280Google Voice
> ∞ This email is: [ ] bloggable [x] ask first [ ] private
> ∞ Google me:http://www.google.com/search?q=andrew%20badera
>
>
>
> On Wed, Nov 11, 2009 at 1:15 AM, pipigu85 <pipig...@gmail.com> wrote:
>
> > I'm not sure. The code is basically what i put with it getting some
> > other data like the date, link. All seems fine except this ommitting
> > content problem.
>
> > Even when i change to event.toString() in place of asCharacters(), it
> > still ommits out the information so it should not be due to
> > asCharacters() right?
>
> > Sorry, I'm still very new to all these Java, hoping someone could help
> > enlighten me.- Hide quoted text -
>
> - Show quoted text -

Andrew Badera

unread,
Nov 11, 2009, 7:44:20 PM11/11/09
to twitter-deve...@googlegroups.com
So, is the message complete in the raw XML response but not after the
Java toCharacters() call?

∞ Andy Badera
+1 518-641-1280 Google Voice


∞ This email is: [ ] bloggable [x] ask first [ ] private
∞ Google me: http://www.google.com/search?q=andrew%20badera

pipigu85

unread,
Nov 11, 2009, 9:26:45 PM11/11/09
to Twitter Development Talk
Yes so was thinking something went wrong with the code that results in
it ommitting out those response with the double quotation

Tried to print out the items retrieved.
When i reach here


while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();


Tried System.out.println(event);
the full content can still be seen. But when i reach here:

if (event.isStartElement()) {
StartElement startElement = event.asStartElement();


The sentences with the double quotation seems to have disappeared.

On Nov 12, 8:44 am, Andrew Badera <and...@badera.us> wrote:
> So, is the message complete in the raw XML response but not after the
> Java toCharacters() call?
>
> ∞ Andy Badera
> ∞ +1 518-641-1280 Google Voice
> ∞ This email is: [ ] bloggable [x] ask first [ ] private
> ∞ Google me:http://www.google.com/search?q=andrew%20badera
>
>
>
> On Wed, Nov 11, 2009 at 7:35 PM, pipigu85 <pipig...@gmail.com> wrote:
>
> > the raw file is in atom format and looks like this:
>
> > <entry>
>
> > <id>tag:search.twitter.com,2005:5607828675</id>
>
> > <published>2009-11-11T02:43:13Z</published>
>
> > <link type="text/html" href="http://twitter.com/green_stormroqr/
> > statuses/5607828675" rel="alternate"/>
>
> > <title>just voted &quot;Selena Gomez&quot; on &quot;Who's your
> > favorite Disney star?&quot;! Vote now  &#10148;http://bit.ly/o2wGh</title>
>
> > <content type="html">just voted &amp;quot;Selena Gomez&amp;quot; on
> > &amp;quot;Who&amp;apos;s your favorite &lt;b&gt;Disney&lt;/b&gt; star?
> > &amp;quot;! Vote now  &#10148; &lt;a href=&quot;http://bit.ly/
> > o2wGh&quot;&gt;http://bit.ly/o2wGh</a></content>
>
> > <updated>2009-11-11T02:43:13Z</updated>
>
> > <link type="image/png" href="http://a3.twimg.com/profile_images/
> > 467518411/061403-1wt_normal.jpg" rel="image"/>
>
> > <twitter:geo>
> >    </twitter:geo>
>
> > <twitter:source>&lt;a href=&quot;http://lolquiz.com"
> > rel=&quot;nofollow&quot;&gt;LOL quiz&lt;/a&gt;</twitter:source>
>
> > <twitter:lang>en</twitter:lang>
>
> > <author>
>
> > <name>green_stormroqr (stormie verrett)</name>
> >      <uri>http://twitter.com/green_stormroqr</uri>
>
> > </author>
>
> > </entry>
>
> > On Nov 12, 12:37 am, Andrew Badera <and...@badera.us> wrote:
> >> What does the RAW XML response look like?
>
> >> Reduce variables. Examine your inputs.
>
> >> ∞ Andy Badera
> >> ∞              +1 518-641-1280        +1 518-641-1280Google Voice
> >> ∞ This email is: [ ] bloggable [x] ask first [ ] private
> >> ∞ Google me:http://www.google.com/search?q=andrew%20badera
>
> >> On Wed, Nov 11, 2009 at 1:15 AM, pipigu85 <pipig...@gmail.com> wrote:
>
> >> > I'm not sure. The code is basically what i put with it getting some
> >> > other data like the date, link. All seems fine except this ommitting
> >> > content problem.
>
> >> > Even when i change to event.toString() in place of asCharacters(), it
> >> > still ommits out the information so it should not be due to
> >> > asCharacters() right?
>
> >> > Sorry, I'm still very new to all these Java, hoping someone could help
> >> > enlighten me.- Hide quoted text -
>
> >> - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages