Calculate the number of Tweets in PHP - php

I want to calculate the number of Tweets of a Twitter Search, and a countup. Just like GigaTweet. How can I calculate this using PHP and the Twitter API?

There are plenty of documents and PHP libraries out there to assist you with this:
http://apiwiki.twitter.com/Libraries#PHP
http://apiwiki.twitter.com/Twitter-API-Documentation
As for the specific method I would use:
- http://apiwiki.twitter.com/Twitter-Search-API-Method:-search
Example:
- http://search.twitter.com/search.atom?q=twitter
I would then use simplexml (http://www.php.net/simplexml) to parse the atom feed. From there I would use the count method to get the number of "entry" items in that feed.
Please keep in mind that the atom format uses xml namespaces and you'll have to use the children method to retrieve items correctly. More on this can be found here: http://www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/

Related

Twitter User Time Line Feed using date parameter

I am working on sentiment analysis for which I need twitter feed. I have implemented the php code to get the json feed and parse it as I wanted. the problem is I could not find a way to get json feed as per the date specified.
$query = array(
'screen_name' => 'twitterapi',
'count' => '5'
);
Using the above syntax I have to specify the number of tweets but my requirement is to get the feed for specific date. Is it possible to pass date parameter instead of count.
currently I am using $path = '/1.1/statuses/user_timeline.json';
I have also implemented the mechanism to manually filter the date but for that I have to provide very large count for older dates that unnecessarily slows down the code.
There are two ways you can do this.
Firstly, read the documentation for the API call you're making. You can't pass a date - but you can request up to 200 Tweets and, if that isn't enough, page through up to 3,200 of their most recent tweets.
Secondly, read the documentation for Searching Twitter, you can use the until parameter to search for older Tweets. Twitter's search API only goes back ~7 days. As they say:
Please note that Twitter’s search service and, by extension, the Search API is not meant to be an exhaustive source of Tweets. Not all Tweets will be indexed or made available via the search interface.

PHP XML of Google News Feed last 24 hours fetch data

I would like to use the GoogleNews XML Feed and use some PHP to style it differently for creating morning news summaries.
QUESTIONS
Is it possible to search for a series of phrases in one xml address. Only one phrase needs to match for it to return results, but all are involved in the search?
e.g.. Fiscal+Cliff,US+Debt
The feed url should only fetch the last 24 hours. My query is not. The problem is with the last 2 variables. What needs to be done to fix it.
xml = http://news.google.com/news?output=rss&num=100&q=fiscal+cliff&as_drrb=q&as_qdr=d
I then want to fetch the <title>, <url> and if possible <author> of each article
Then I want each URL to be used for the PHP to fetch a caption and an image.
$item[title], $item[url] $item[author], Item[image_src], Item[caption]
I would then echo this information how I want it set up on the page. How do I do this?
http://www.queness.com/post/8743/learn-how-to-read-parse-and-display-xml-data-in-random-order-with-jquery
Use google as this question is not unique and you can use xml dom to fetch, parse and display data.

Get feed titles from any RSS feed with php

I'm attempting to build an RSS reader at the moment I'm using php's simplexml using
For example
$xml->item->title
But however this is dependent on the structure of the rss feed itself if the structure is different it won't work so I was wondering if theres a more broader and less specific way to grab all the titles from a RSS feed.
Thanks a lot
There is a RSS Specification document out there. You can find it at http://cyber.law.harvard.edu/rss/rss.html
Therefore, a RSS file always looks the same, but be carefull. There is always something like Atom.
You could use xPATH for searching within the RSS: http://nl.php.net/manual/en/simplexmlelement.xpath.php
maybe it´s an option for you using a contribution like this instead of invent the wheel again: http://www.phpclasses.org/package/3724-PHP-Parse-and-display-items-of-an-RSS-feed.html
You can use some Regex to filter the RSS files and split them into titles, etc. Whatever you want. As you will define which tags to grab data from.
Using something like: $regex = '/<(w+)[^>]*>(.*?)</\1>/s';
preg_match_all($reg_exp, $text, $match);
There are lot of feed formats. Writing code to comply all, is a bit difficult task. so..
I recommend using simple pie. http://simplepie.org/
or you can use google feed api also. here is a example using simple pie.
http://simplepie.org/wiki/setup/sample_page

A Publisher with RSS as Datasource

I am writing some code to fetch news from rss feed and publish n items at once every m hours to another site.
I compare the update xml file with the previous one saved on server using PHP.
I load the two xml into php array and the latest post is filter out using array_diff_assoc().
If the number of the latest post>n, the older one will be publish first, the rest will be done next time. Therefore I need some ways to store which item have publish or not.
What is the simplest way to do so? I don't want to apply mySQL/S for such a simple task.
Can't you just store those not published? Then each time, pull up the old, stored ones, and append to the list those new ones ID'd by array_diff_assoc(). Publish n, and if number > n, store the new list of unpublished ones.
As to how to store them, I'm not a PHP programmer, but what about using PHP's serialize and unserialize functions? In python, I'd use the pickle module if I had to store data objects of some type, and I understand those are the PHP equivalent.

Seeking a PHP script to filter an RSS feed

I have about 50 feeds (and growing) that I would like to filter before adding them to Google Reader. Each of the feeds will be filtered for the same keywords. If a keyword match is found, that item will be removed from the feed. Basically I'm just trying to eliminate some noise.
I know I can do this with Yahoo Pipes, but I'm looking for a self-hosted solution.
I'd like to pass a feed to a script on my server. That script will filter out unwanted feed items based on a list of defined keywords. The filtered feed will be the result. I plan to then add the feed to Google Reader.
(BTW, why doesn't Google Reader have filters like Gmail?)
Try using a RSS library like Simplepie. From there, writing the filter logic should be easy-peasy.
Try ReFilter. Looks nice.

Categories