Twitter API with PHP
In order to use a communicante with a website ( in this case twitter) , we need to call it's api
But there too many standars to communicate with api ( OAuth1, OAuth2...) , hopefully they provides api documentation .
In this tutoriel we are gonna use twitter api (1.1 ) as exemple to get ou last tweets , but first we have to create twitter application
Creating twitter application give us some random strings `consumer_secret`, `consumer_key`, `access_token` and `access_token_secret`
We will use these strings later in OAuth process.
Don't panic no need to knowing all OAuth process using php , Moreover, there are many php libraries and packages to do this for us , there is a very popular one ( twitter-api-php )
first we create an empty folder for our project then require the package :
composer require j7mbo/twitter-api-php
copy and past random strings from your twitter application in to this array
variable :
With twitter api we can do many things like post status , sign in with twitter ..., integrating social features may be a good thing to your application .
But there too many standars to communicate with api ( OAuth1, OAuth2...) , hopefully they provides api documentation .
In this tutoriel we are gonna use twitter api (1.1 ) as exemple to get ou last tweets , but first we have to create twitter application
Creating twitter application give us some random strings `consumer_secret`, `consumer_key`, `access_token` and `access_token_secret`
We will use these strings later in OAuth process.
Don't panic no need to knowing all OAuth process using php , Moreover, there are many php libraries and packages to do this for us , there is a very popular one ( twitter-api-php )
first we create an empty folder for our project then require the package :
composer require j7mbo/twitter-api-php
copy and past random strings from your twitter application in to this array
variable :
$settings = array( 'oauth_access_token' => "YOUR_OAUTH_ACCESS_TOKEN", 'oauth_access_token_secret' => "YOUR_OAUTH_ACCESS_TOKEN_SECRET", 'consumer_key' => "YOUR_CONSUMER_KEY", 'consumer_secret' => "YOUR_CONSUMER_SECRET" );
we need also to create a url variable of api endpoint :then we instante twitter variable with our application keys ,lastly we call the get status api ans save the status as json object ,
With twitter api we can do many things like post status , sign in with twitter ..., integrating social features may be a good thing to your application .
Comments
Post a Comment