I have an idea for a Twitter snippet, that pulls the latest tweets from the Twitter API JSON feed, and only pulls it like once per day, or once every 12 hours, or at whatever interval the user sets, and displays however many results the user wants. Should be somewhat simple, but I can't code it myself, although the logic and the thoughts needed to get it to do what I want I have. I'm looking to either pay someone to code it for me, or I'll put up the bounty so that when the snippet is coded you can release it on modx.com and others can use it as well, not sure. Let me know what you think please! How much, how doable, etc.
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
Getting stuff from the Twitter API is definitely doable, but the timing issue is a problem, because MODX isn't actually running when no one is visiting the site. If you want precise timing, you'd have to create a cron job, otherwise, the code would only execute when someone visited the site.
You should also specify whether you need a CMP (Custom Manage Page) for this or just a snippet on a page that the user could visit to see the results.
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html
@microcipcip I'm not looking to do it with javascript, especially not if it is done in jQuery. I don't see the need to add overhead of 2-4 files to be requested from the server, in addition to probably close to 100kb all told, to display 1 or 2 measly tweets. Twitter has utterly failed in my opinion, by making this so difficult to do with only a few lines of code...
@BobRay, sorry, I forgot to mention: I'd be working in Evo, but I'll bet the snippet is pretty much the same for both, logic-wise, and would need to be modified slightly to work in the other.
The timing is something I thought of; I know that about MODX. What I realized is that when no one is at the site, no one cares either, but if someone does visit the site, have MODX run a check from the current timestamp to the timestamp held in a database or a flatfile db; say we want an hour between checks. If timestamp(now) is greater than timestamp(then)+3600 seconds, then re-run the script asking Twitter for the new information. This gets rid of the need for a CRON job, allowing the script to only execute when someone is at the site, and still saving the information for anyone else that visits the site within the next hour, or 24 hours, or whatever...
Additionally, because Twitter lags sometimes, and because I know that most tweets are not so vitally important that they need to be to the minute (in situations I'm likely to encounter), I would even have the script time Twitter's response, and if it is taking longer than say 1.5 seconds, I'd have the script cancel itself and display the old tweets. If that timer turns out to be too short, then the timer can be edited.
Not sure what you mean about a CMP, is that a Revo thing? I've built a few HTML templates that have a small twitter feed in them, displaying tweets from the user on their own website. I would only need the tweets, plus some other data in different cases (sometimes the link to the tweet, sometimes the date of the tweet, reformatted to be human-friendly) put into placeholders that can be dropped into a tiny tpl and put into an HTML template, either in the footer or the sidebar.
I know I had seen an easy way to do this, but Twitter switched around their whole API and deprecated the old things. I've spent hours upon hours looking for a quick and easy fix (to no avail), but I actually like this idea better, as it takes into account the weaknesses of twitter and addresses them, while not being a resources hog (most of the time I'd implement it I'd have it checking once per day, or once per day and a half).
Let me know what you think...
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
Ah yes, I forgot to mention: I know a lot of people put jQuery into sites automatically, in which case I agree, a few lines of JS code, and voila, twitter feed. I still think Twitter has messed up big making it so techie to display a few latest tweets, but that's my own feeling...
In most cases I'm not calling jQuery, or if I am, it is either on the homepage or on very specific pages where I need to use it for one or two things. I work very hard to make sure my code is usable and good without using jQuery or any JS for that matter, as it relies on cleaner code, and makes for faster downloads and less requests, as well as being the same code whether the user has JS turned on or off.
In any case, those all look as though they may work; they may need me to hack them to do what I want, which is not my ideal solution, but they certainly seem as though they have potential. Thanks for the leads. Funny, I looked in the MODX repository using the Search function and I don't think I saw the last two...
Thanks! I'd probably still be willing to pay a bounty or a fee if someone is interested in rolling something custom with the specs I've mentioned??
"Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein
Ugh. After a few hours of screwing around, I got this to work with twitteroauth.php. Then, I discovered that you don't need authorization just to pull tweets (just shoot me). You must set either &screenName or &userId -- the other properties are optional. &includeRts defaults to true. Note that if you set it to false, you won't get any tweets back if the first 'count' tweets are all retweets.
Properties:
&screenName
&userId
&count
&includeRts (include retweets)
[[!ShowTweets? &screenName=`BobRay` &count=`5`]]
<?php
/* ShowTweets snippet */
$sp =& $scriptProperties;
$screenName = isset($sp['screenName'])? '&screen_name=' . $sp['screenName'] : '';
$id = isset($sp['userId'])? '&id=' . $sp['userId'] : '';
$count = isset($sp['count'])? '&count=' . $sp['count'] : '';
$includeRts = isset($sp['includeRts'])? $sp['includeRts'] : '1';
$url = 'http://api.twitter.com/1/statuses/user_timeline.json?include_rts=' . $includeRts . $id . $screenName . $count;
$tw = curl_init();
curl_setopt($tw, CURLOPT_URL, $url);
curl_setopt($tw, CURLOPT_RETURNTRANSFER, TRUE);
$twi = curl_exec($tw);
$twi = json_decode($twi);
//echo var_dump($twi);
$output = '';
foreach ($twi as $tweet) {
$output .= 'Time: ' . $tweet->created_at . "<br />";
$output .= 'Tweet: ' . $tweet->text . "<br /><br />";
}
curl_close($tw);
return $output;
I don't see the need for a timer, since you'd always want the most recent tweets, no?
Feel free to contribute at
http://bobsguides.com/support-this-site.html.
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html
[ed. note: BobRay last edited this post 14 years, 4 months ago.]
I see the forum is still mangling URLs in code. The line should be
$url = '
http://api.twitter.com/1/statuses/user_timeline.json?include_rts=' . $includeRts . $id . $screenName . $count;
The OP was talking about saving the tweets, I believe the idea being that it would make things quicker - one would not have to download the tweets for every page load, and wait while twitter responded before building the page - this is an advantage a js based feed has - the rest of the page can be downloaded and displayed without having to wait for the twitter feed.
My idea was to make this work was by cacheing the results - which would be easy to do, just call the tweet fetching snippet cached - but set a time limit on the cached resource - after the time was up the next request for the resource would call the snippet again, updating the tweets.
I don't know whether this could be easily done with evo or not - in revo I believe the time cacheing expiration is a new feature so implementation details would vary based on the modx versions - and may be somewhat simple only for the most recent version(?s) of revo