50% of the time receiving 500 Internal Server Error user_timeline


#1

I have a simple application that loads the last 20 tweets from a given user.
The request is for xml.

Everything works fine when I test on my local server, but once I upload it to the site (WordPress), 50% of the time it works and 50% it doesn’t and I get the “NetworkError: 500 Internal Server Error.”

This is the part of the request that faces the problem:

$xmldata = 'http://twitter.com/statuses/user_timeline/' . $user_name . '.xml';
$open = fopen($xmldata, 'r');
$content = stream_get_contents($open);
fclose($open);
$xml = new SimpleXMLElement($content);

The error log file says:
PHP Fatal error: Uncaught exception ‘Exception’ with message ‘String could not be parsed as XML’

There is obviously nothing wrong with the code if it is actually working some of the time, or else it wouldn’t work at all.

Any ideas on what’s causing this error?
Is this a problem with the xml response from twitter?

Thank you.


#2

Well you’re not requesting a supported API endpoint. The endpoint you want is documented here: https://dev.twitter.com/docs/api/1/get/statuses/user_timeline

So there is something wrong with this code :wink:


#3

First of all, you’re right. Silly me.
But if I am using the wrong API endpoint, how come it works on a local server (and half of the time on public)?

Second, when I use http://api.twitter.com/1/statuses/user_timeline/ I still have the same problem.
Does this mean I have to use the authenticated one?
https://api.twitter.com/1/statuses/user_timeline.json

Thank you!


#4

Does the request fail consistently with certain names, or is it just random?


#5

Any name that I use…


#6

I tried using a different approach, using the search api and search for tweets ‘from:user_name’.
That only gives me 3 results although I can see on the user’s page there are plenty of tweets…


#7

There must be something set in your environment that’s causing the request to fail. For example, any of the ini_set(“user_agent”, …) hacks described in http://www.php.net/manual/en/wrappers.http.php have a good chance of breaking something.

It would be very useful to get a full dump of the response text and headers. The exact URL you’re sending would be good to have too.


#8

The problem is that I don’t get a response when I put it on the remote server. I get the network error.

I pasted the response that I get on my local server, I don’t know if that will help…
I can only paste here the first result though.

The url I am using for the request is :
http://api.twitter.com/1/statuses/user_timeline/thebeatles.xml

SimpleXMLElement Object ( [@attributes] => Array ( [type] => array ) [status] => Array ( [0] => SimpleXMLElement Object ( [created_at] => Mon Nov 14 12:09:26 +0000 2011 [id] => 136053121662189569 [text] => Help support the mobile studio that's a living legacy to John's belief in artistic expression by "Liking" their FB page http://t.co/zqgKk9h8 [source] => web [truncated] => false [favorited] => false [in_reply_to_status_id] => SimpleXMLElement Object ( ) [in_reply_to_user_id] => SimpleXMLElement Object ( ) [in_reply_to_screen_name] => SimpleXMLElement Object ( ) [retweet_count] => 100+ [retweeted] => false [user] => SimpleXMLElement Object ( [id] => 27760317 [name] => The Beatles [screen_name] => thebeatles [location] => Liverpool, UK [description] => The Official Beatles Twitter Page [profile_image_url] => http://a0.twimg.com/profile_images/443035866/BeatlesBack_inv_normal.jpg [profile_image_url_https] => https://si0.twimg.com/profile_images/443035866/BeatlesBack_inv_normal.jpg [url] => http://twitter.com/thebeatles [protected] => false [followers_count] => 551017 [profile_background_color] => C0DEED [profile_text_color] => 333333 [profile_link_color] => 0084B4 [profile_sidebar_fill_color] => DDEEF6 [profile_sidebar_border_color] => C0DEED [friends_count] => 357281 [created_at] => Mon Mar 30 23:31:05 +0000 2009 [favourites_count] => 0 [utc_offset] => -28800 [time_zone] => Pacific Time (US & Canada) [profile_background_image_url] => http://a1.twimg.com/profile_background_images/55917251/Twitter_Background.jpg [profile_background_image_url_https] => https://si0.twimg.com/profile_background_images/55917251/Twitter_Background.jpg [profile_background_tile] => false [profile_use_background_image] => true [notifications] => false [geo_enabled] => false [verified] => true [following] => true [statuses_count] => 251 [lang] => en [contributors_enabled] => false [follow_request_sent] => false [listed_count] => 13118 [show_all_inline_media] => false [default_profile] => false [default_profile_image] => false [is_translator] => false ) [geo] => SimpleXMLElement Object ( ) [coordinates] => SimpleXMLElement Object ( ) [place] => SimpleXMLElement Object ( ) [possibly_sensitive] => false [contributors] => SimpleXMLElement Object ( ) )

#9

Getting Internal 500 error
| Error 2014-02-06 11:58:29,789 [http-bio-8080-exec-8] ERROR errors.GrailsExceptionResolver - IllegalArgumentException occurred when processing request: [GET] /mvp/oauth/twitter/authenticate
Cannot get String from a null object. Stacktrace follows:
Message: Cannot get String from a null object
Line | Method
->> 82 | check in org.scribe.utils.Preconditions


| 29 | checkNotNull in ‘’
| 20 | getStreamContents in org.scribe.utils.StreamUtils
| 41 | parseBodyContents in org.scribe.model.Response
| 67 | getBody . . . . . in ‘’
| 48 | getRequestToken in org.scribe.oauth.OAuth10aServiceImpl
| 67 | doCall . . . . . in uk.co.desirableobjects.oauth.scribe.OauthController$_closure2
| 195 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter . . . . in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run in java.lang.Thread


#10

Hi, I would like to know how to implement the code in my application for post the Image/Picture to twitter using twitter4j.

Thanks in Advance,
Chandra


#11

Hi, I was not able to create an application in https://dev.twitter.com/ for getting consumer key and consumer secret. It was saying that “Your account is suspended and is not permitted to access this feature” when I submit the Application details under Create an application page.

Please some one help/guide me what needs to be done to create the application successfully.

Best Regards,


#12

#13