• Home
  • Who Am I?
  • Contact Me

Viral Solani

If you can't do it, I will love to do it….
Stay updated via RSS

  • Blog Stats

    • 26,669 hits
  • My Stackoverflow Profile

    profile for Viral Solani at Stack Overflow, Q&A for professional and enthusiast programmers
  • Categories

    • Apache (1)
    • Cool Articles (27)
    • Drupal (2)
    • Facebook (1)
    • Funny Video (1)
    • General (13)
    • htaccess (1)
    • Javascript (4)
    • Jquery (4)
    • Motivatioanl Stories (11)
    • My-SQL (16)
    • MySQL Joins (5)
    • OOPS Consept (2)
    • PHP (37)
    • Regular Expression (1)
    • Twitter (1)
    • Ubuntu (2)
    • Uncategorized (2)
    • Zend Framework (6)
  • My Tweets

    • "Only he/she who does Nothing makes No Mistakes".:) | 19 hours ago
    • @nbknaresh thanks dude...but not heavely....normal rain will be fine :) :) | 1 day ago
    • Go ahead. #BeHappy now. There's no need to save your #happiness for the future. You can always make much more. | 1 day ago
    • RT @ydn: PHP Mobile Detect is a lightweight PHP class for detecting mobile devices, including tablets and smartphones. http://t.co/wxgB1Cpe… | 1 day ago
    • Just because you fail once, doesn't mean you're gonna fail at everything. Keep trying and believe in yourself! #quote | 2 days ago
    • RT @planetphp: 5 Reasons Why the Web Platform War is Over: PHP Won with 75% says Google - PHP Classes planet-php.org/~o2j | 2 days ago
    • @nbknaresh lucky you...we are eagerly waiting for rain here in Ahmedabad...temp. goes high and high day by day.... | 2 days ago
    • How to replace plain URLs with links in JavaScript or PHP? wp.me/p11obe-7P | 4 days ago
    • @1Prachidesai Both pics are good. but second one is superb..go with it.. | 4 days ago
    • RT @juniorbachchan: “@bombayblue: What a brilliant Ad! Should make more like these. 'For your Mother's sake... Wear a helmet!' http://t.co/… | 4 days ago
  • Latest Post

    • How to replace plain URLs with links in JavaScript or PHP?
    • 8 Things Productive People Do During the Workday
    • Set php.ini Values Using .htaccess
    • Prevent Your CSS and JavaScript Files From Being Cached
    • Android Detection with JavaScript or PHP
  • Monthly Archive

    • May 2013 (2)
    • February 2013 (4)
    • January 2013 (1)
    • December 2012 (1)
    • September 2012 (1)
    • May 2012 (3)
    • April 2012 (1)
    • March 2012 (1)
    • January 2012 (1)
    • December 2011 (1)
    • November 2011 (1)
    • October 2011 (6)
    • September 2011 (4)
    • August 2011 (19)
    • July 2011 (12)
    • June 2011 (3)
    • May 2011 (10)
    • April 2011 (9)
    • March 2011 (5)
    • February 2011 (1)
    • December 2010 (2)
    • November 2010 (9)
    • October 2010 (5)
    • September 2010 (2)
  • Blogroll

    • Hardik Patel
    • Motivational Memo
    • Mrunal Choksi
    • My Facebook Profile
    • My Google Profile
    • My LinkedIn Profile
    • My Twitter Profile
    • Rupesh Patel
    • Yahoo Education
    • Yahoo LifeStyle
  • Top Rated

  • Top Posts

    • Automatically refresh the web page every 5 seconds, with PHP
    • Move (Copy) Div From One Place To Another Using jQuery
    • Normalization Basics – 1NF 2NF and 3NF
    • Zend Framework SQL Joins Examples
    • Difference between require, require_once, include and include_once
    • EXE in PHP (Make Executable or Make Desktop Application in PHP)
    • how to make Alphabet Navigation Menu with PHP?
    • Find Number of Child Elements (Length) Using jQuery
    • How to integrate paypal pro in to your php site....
    • How to install SSL Certificates with Apache 2 on Ubuntu 12.04
  • Apache Cool Articles Drupal Facebook Funny Video General htaccess Javascript Jquery Motivatioanl Stories My-SQL MySQL Joins OOPS Consept PHP Regular Expression Twitter Ubuntu Uncategorized Zend Framework
  • Tag Cloud

    connect to multiple MySQL databases on a single webpage Drupal Facebook Find Highest Salary Frameworks Funny Video Goal Having Clause - MySQL htaccess HTML JavaScript Joins in Zend Framework jquery Languages LinkedIn Model–view–controller Motivation Motivational Articles Motivational Quotes Motivational Stories Multilanguage Site Using Arrays MySQL MySQL Injection Attacks MySQL INNER JOIN MySQL INNER JOIN With comma operator MySQL interview questions My Sql Joins MySQL JOINS MySQL LEFT JOIN MySql Outer Joins MySQL RIGHT JOIN Nine Ways to use LinkedIn to Advance your Career OOPS consents in PHP Optimism PHP PHP Interview Question PHP Magic Constants PHP Magic Constants __LINE__ And __FILE__ Programming Skill The Top Most Inspirational Quotes About Life Web development Zend Framework Zend Framework: Storing session data in database Zend Framework SQL Joins Examples
  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 113 other followers

Writing Your First Twitter Application with oAuth

Posted: May 26, 2012 in PHP, Twitter
Tags: Fetch data from twitter, Writing Your First Twitter Application with oAuth
0

Hello Friends

In My current application There is requirement to fetch twitter timeline for the particular user. So I’ve fetched it with the help of Rest API of twitter an oAuth.

OAuth is an open protocol to allow secure API authorization in a simple and standard method from desktop and web applications. In layman’s terms, it is a system by which you can allow a user to authenticate with an OAuth-enabled service without providing you with their credentials to that service.

Why OAuth?

Using OAuth allows you to write applications that access the Twitter API but do not require your users to give you their Twitter username and password. This is important for a variety of reasons:

  • If the user changes their Twitter login, they do not have to update that information with you for your application to continue working for them
  • Using OAuth puts the user in control – if they ever wish to stop using your application, they can disable it through Twitter instead of trusting your application to stop using their login information. Once they disable it through Twitter, any requests by your application will require them to manually approve the connection again.
  • Increased sense of trust, since the user doesn’t have to worry about your application stealing their Twitter credentials and using it for nefarious purposes. I personally wouldn’t trust any web-based application that asks for my Twitter username and password, and given Twitter’s recent history of bad press regarding their security, more and more users are following that lead.

Getting Started – Registering Your Application with Twitter

First of all , you have to register your new application with Twitter. You’ll need a name and url for your application in order to register it, and you’ll need to define a callback url. The callback url is the full url of the page Twitter should send the user to after it’s done authenticating. This file can be named anything you want, but make sure the one you create on your server matches the one you register with Twitter. All of these details can be changed later if you change your mind or need to update something.

Once you’ve registered your application, Twitter will issue you a Consumer Key and a Consumer Secret for your new app. You’ll need these to get your sample code from the Twitter OAuth library working. As you can probably tell by the name, your Consumer Secret should remain private and you should never give it out to anyone. It’s used in your code so that Twitter can identify your application when you’re making API calls.

By forcing you to send your consumer key and secret with your API calls, Twitter is able to determine which application is sending the API calls, and can verify that the Twitter user you are attempting to send API requests on behalf of has actually authorized your application to access their account. If the user decides they no longer want to allow your application, they can edit their allowed application preferences and your application will no longer be able to make API calls on their behalf.

You can access a list of all of the applications you have registered with Twitter – and links to edit their details or view the consumer key and consumer secret – by going to your oauth clients page on Twitter.

The Twitter OAuth PHP Library Code

There are several oAuth Twitter -libraries for PHP. But I Recommend Abraham’s Twitter OAuth library . You can pull the code from http://github.com/abraham/twitteroauth.

This library does provide an example script. You need to replace your Consumer Key and a Consumer Secret in confing.php. Please check that callback.php file should be one that we’ve registered with Twitter as being our callback url. We can keep common configuration options such as the consumer key and consumer secret, and database credentials in a config.php file. Now you can run index.php.

Now in your callback.php you can save access_token in database for future request. You can use that access token to call the APIs and you don’t need to enter Twitter user name and password.

/* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
/* Request access tokens from twitter */
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);

Here you can dowanload the whole code from git hub. you just need to put your Consumer Key and a Consumer Secret in config.php and need to check callback url settings it should be demo’s callback.php and than you can run index.php you will get the result.

https://github.com/viralsolani/twitter-oAuth-example

Important Links

  • Register your application with Twitter
  • List of all of your registered apps on Twitter
  • Twitter API Documentation
  • Twitter API Rate Limiting Documentation
  • Download & Docs for Abraham’s OAuth PHP library
  • OAuth official website
  • http://net.tutsplus.com/tutorials/php/creating-a-twitter-oauth-application/
  • http://140dev.com/twitter-api-programming-tutorials/hello-twitter-oauth-php/

Hope it helps

 

About these ads

Rate this:

Share this:

  • Share
  • Facebook
  • Twitter
  • Google +1
  • LinkedIn
  • Email

Like this:

Like Loading...

Leave a Reply Cancel reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. ( Log Out / Change )

Twitter picture

You are commenting using your Twitter account. ( Log Out / Change )

Facebook photo

You are commenting using your Facebook account. ( Log Out / Change )

Cancel

Connecting to %s

PHP SDK & Graph API base Facebook Connect Tutorial
The Painting

Blog at WordPress.com. | Theme: Greyzed by The Forge Web Creations.
Follow

Get every new post delivered to your Inbox.

Join 113 other followers

Powered by WordPress.com
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.
%d bloggers like this: