Mobzab is a mobile frontend for Zabbix which can be used on any mobile device. The frontend is optimized for usage with iOS, Android and Windows Mobile. It uses the Zabbix API to safely communicate with the Zabbix backend. I use it for a while now and i think it’s really cool! take a look at http://www.mozbx.net/index.html for more info and download!
Tag Archives: php
PHP Twitter OAuth integration
I’ve added an HOWTO to explain how to integrate Twitter’s Oauth authentication method with your own PHP pages. After batteling quite some time to get it working i decided to document a working approach to avoid future integration problems. Feel free to take advantage of the examples listed at this page: http://wouter.borremans.nl/computer-related/programming/php/twitter-oauth-integration/
PHP Twitter OAuth integration
This is a small how-to for integrating Twitter status updates into your website using PHP.
After succesfully using basic authentication for several months, twitter introduced a new authentication method Oauth as of August 31 2010.
This meant that i had to look for a solution to rewrite several lines of code to enable the website to post tweets using the new method. This is a small howto to integrate the new OAuth method using a quite old PHP 5 version.
Prerequisites
- Basic programming skills
- Web- and FTP server access
- PHP 5.1.6+
- PEAR JSON Class (if you’re not on PHP >=5.2.0)
- Registered application at dev.twitter.com
- Oauth token and Oauth secret
- Abraham Williams’ PHP Oauth library
Installation
Well, let’s get started, first and most important thing to do is to let Twitter know that you’re creating an application that want’s to post tweets:
- Go to http://dev.twitter.com and make sure you’ve signed in by using your already existing twitter account
- Register a new app using the button on the upper righthand side of the page
- Make sure you fill all the required field with genuine information, specifically pay attention to the following fields/choices:
- Application Type -> Choose for ‘Browser’
- Callback URL -> Choose a path where you will install your php files; http://<your.tld>/<path>/callback.php
- Default Access type -> Choose for ‘Read & Write’
- Click Register and agree with the terms of serivce, your application is now registered!
- An important page is shown now, make sure you keep the listed details somewhere safe, for this howto you will need the following:
- Consumer key
- Consumer secret
- My Access Token (not listed directly, but can be viewed by clicking the ‘My Access Token’ on the right side of the page.
The application is now registered at dev.twitter.com, please make sure that you download the following files:
- Abraham Williams’ PHP Oauth library [Download from author’s website here]
If you’re not on PHP >=5.2.0:
- PHP PEAR JSON Class [Download from author’s website here]
Now we’re at the point that we can create the twitter application on the webserver:
- Unzip both downloaded files and upload them to your webserver (make sure you’re on the right PHP version using the PEAR JSON Class)
- If not on PHP >= 5.2.0 make sure you include the following piece of code somewhere before getting at the twitter part/including the Oauth library: (sorry for being a bit vage)
if (!function_exists('json_decode')) { function json_decode($content, $assoc=false) { require_once '/JSON.php'; if ($assoc) { $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); } else { $json = new Services_JSON; } return $json->decode($content); } } |
Configurion of OAuth Library
At this point you have to configure the Oauth library to let it communicate with the Twitter API:
- Go to the path on your FTP server where you’ve uploaded both or separeate classes
- Edit config.php and make sure you list your customer key, consumer secret and callback url as you listed it at dev.twitter.com
- Edit twitteroauth.php in the twitteroauth folder, make sure you change the following piece of code:
/** * Set API URLS */ function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; } function authenticateURL() { return 'https://twitter.com/oauth/authenticate'; } function authorizeURL() { return 'https://twitter.com/oauth/authorize'; } function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; } |
To:
/** * Set API URLS */ function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; } function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; } function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; } function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; } |
Integration with your PHP Code
Now integrate this piece of code into your php page where you want to post tweets to Twitter:
function getConnectionWithAccessToken($oauth_token, $oauth_token_secret) { $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret); return $connection; } // Create a connection with Twitter API using access tokens $connection = getConnectionWithAccessToken("YOUR_OAUTH_TOKEN", "YOUR_OAUTH_TOKEN_SECRET"); // Post message to twitter $content = $connection->;post('statuses/update', array('status' =>; 'YOUR_TWEET')); |
To debug the connection between the Twitter API and your code, use for example print_r($content).
I used the following sites to be able to make the above howto:
- Using one access token with OAuth, http://dev.twitter.com/pages/oauth_single_token#php
- PHP PEAR Services JSON, http://pear.php.net/pepr/pepr-proposal-show.php?id=198
- Abraham Williams, OAuth Library, https://github.com/abraham
Programming / Scripting
Programming
Follow this guide when you would like to integrate Twitter on your own website using the latest OAuth Authentication method.
Scripting
Have a look at several scripts which i wrote for to solve practical issues on my Ubuntu server.