Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/J7mbo/twitter-api-php int…
Browse files Browse the repository at this point in the history
…o develop
  • Loading branch information
JamesMallison committed May 11, 2015
2 parents 208823f + 4f3e89f commit a29fbf9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 29 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!
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
"ext-curl": "*"
},
"require-dev": {
"phpunit/phpunit": "4.5.1"
"phpunit/phpunit": "~4.5,>=4.5.1"
},
"name": "j7mbo/twitter-api-php",
"description": "Simple PHP Wrapper for Twitter API v1.1 calls",
"version": "1.0.0",
"type": "library",
"keywords": [
"twitter",
Expand All @@ -24,5 +23,10 @@
],
"autoload": {
"files": ["TwitterAPIExchange.php"]
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
}
}

0 comments on commit a29fbf9

Please sign in to comment.