danvin-test / twitter-activity
Simple PHP Twitter User Activity Checker
Requires
This package is not auto-updated.
Last update: 2025-03-23 09:01:29 UTC
README
This small web app takes user's twitter screen name as a parameter and return a JSON-encoded array containing "hour -> tweets count" for a given user, to determine what hour of the day they are most active. It also provides demonstration of the Silex's routing.
Requirements
- PHP 7.1.3 or later
- Enabled PHP CURL module
- Enabled mod_rewrite module (only for usage on webserver)
Installation
-
Install Composer
curl -s https://getcomposer.org/installer | php
-
Execute
php composer.phar create-project danvin-test/twitter-activity project_name
Configuration
Twitter API Credentials
Edit config.json, located in the root folder of the project, to set up your Twitter API credentials.
Notable mention: This web app uses statuses/user_timeline Twitter API. Advanced configuration available in the config.json, under twitterRequestSettings
section.
.htaccess
If your site is not at the webroot level you will have to uncomment the RewriteBase statement and adjust the path to point to your directory, relative from the webroot. More information available at the Silex Webserver Configuration page
Usage
The application has 3 endpoints:
- "/" - will respond with "Try /hello/:name" as text
- "/hello/Daniel" - will respond with “Hello Daniel” as text
- "/histogram/Ferrari" - will respond with a JSON-encoded array displaying the number of tweets per hour of the day. Most active hours will be presented at the top of the array.
CLI
php index.php GET /
php index.php GET /hello/Daniel
php index.php GET /histogram/Ferrari
WebServer
http://localhost/
http://localhost/hello/daniel
http://localhost/histogram/Ferrari
Running the tests
-
Make sure you have PHPUnit installed.
-
To execute the tests, navigate into your project's folder and run
phpunit