Skip to content

Commit

Permalink
Merge pull request #75 from Narno/master
Browse files Browse the repository at this point in the history
Highlighting of source code
  • Loading branch information
J7mbo committed May 11, 2015
2 parents 28e50e3 + 4f97c06 commit d403875
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
twitter-api-php
======================
===============

Simple PHP Wrapper for Twitter API v1.1 calls

[![Total Downloads](https://poser.pugx.org/j7mbo/twitter-api-php/downloads.png)](https://packagist.org/packages/j7mbo/twitter-api-php)
Expand Down Expand Up @@ -40,51 +41,64 @@ Installation
Of course, you'll then need to run `php composer.phar update`.

How To Use
------
----------

#### Include the class file ####

require_once('TwitterAPIExchange.php');
```php
require_once('TwitterAPIExchange.php');
```

#### Set access tokens ####

$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"
);
```php
$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"
);
```

#### Choose URL and Request Method ####

$url = 'https://api.twitter.com/1.1/blocks/create.json';
$requestMethod = 'POST';
```php
$url = 'https://api.twitter.com/1.1/blocks/create.json';
$requestMethod = 'POST';
```

#### Choose POST fields ####

$postfields = array(
'screen_name' => 'usernameToBlock',
'skip_status' => '1'
);
```php
$postfields = array(
'screen_name' => 'usernameToBlock',
'skip_status' => '1'
);
```

#### Perform the request! ####

$twitter = new TwitterAPIExchange($settings);
echo $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
```php
$twitter = new TwitterAPIExchange($settings);
echo $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
```

GET Request Example
----------------
-------------------

Set the GET field BEFORE calling buildOauth(); and everything else is the same:

$url = 'https://api.twitter.com/1.1/followers/ids.json';
$getfield = '?screen_name=J7mbo';
$requestMethod = 'GET';
```php
$url = 'https://api.twitter.com/1.1/followers/ids.json';
$getfield = '?screen_name=J7mbo';
$requestMethod = 'GET';

$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
```

That is it! Really simple, works great with the 1.1 API. Thanks to @lackovic10 and @rivers on SO!

0 comments on commit d403875

Please sign in to comment.