|
1 | 1 | twitter-api-php
|
2 |
| -====================== |
| 2 | +=============== |
| 3 | + |
3 | 4 | Simple PHP Wrapper for Twitter API v1.1 calls
|
4 | 5 |
|
5 | 6 | [](https://packagist.org/packages/j7mbo/twitter-api-php)
|
@@ -40,51 +41,64 @@ Installation
|
40 | 41 | Of course, you'll then need to run `php composer.phar update`.
|
41 | 42 |
|
42 | 43 | How To Use
|
43 |
| ------- |
| 44 | +---------- |
| 45 | + |
44 | 46 | #### Include the class file ####
|
45 | 47 |
|
46 |
| - require_once('TwitterAPIExchange.php'); |
| 48 | +```php |
| 49 | +require_once('TwitterAPIExchange.php'); |
| 50 | +``` |
47 | 51 |
|
48 | 52 | #### Set access tokens ####
|
49 | 53 |
|
50 |
| - $settings = array( |
51 |
| - 'oauth_access_token' => "YOUR_OAUTH_ACCESS_TOKEN", |
52 |
| - 'oauth_access_token_secret' => "YOUR_OAUTH_ACCESS_TOKEN_SECRET", |
53 |
| - 'consumer_key' => "YOUR_CONSUMER_KEY", |
54 |
| - 'consumer_secret' => "YOUR_CONSUMER_SECRET" |
55 |
| - ); |
| 54 | +```php |
| 55 | +$settings = array( |
| 56 | + 'oauth_access_token' => "YOUR_OAUTH_ACCESS_TOKEN", |
| 57 | + 'oauth_access_token_secret' => "YOUR_OAUTH_ACCESS_TOKEN_SECRET", |
| 58 | + 'consumer_key' => "YOUR_CONSUMER_KEY", |
| 59 | + 'consumer_secret' => "YOUR_CONSUMER_SECRET" |
| 60 | +); |
| 61 | +``` |
56 | 62 |
|
57 | 63 | #### Choose URL and Request Method ####
|
58 | 64 |
|
59 |
| - $url = 'https://api.twitter.com/1.1/blocks/create.json'; |
60 |
| - $requestMethod = 'POST'; |
| 65 | +```php |
| 66 | +$url = 'https://api.twitter.com/1.1/blocks/create.json'; |
| 67 | +$requestMethod = 'POST'; |
| 68 | +``` |
61 | 69 |
|
62 | 70 | #### Choose POST fields ####
|
63 | 71 |
|
64 |
| - $postfields = array( |
65 |
| - 'screen_name' => 'usernameToBlock', |
66 |
| - 'skip_status' => '1' |
67 |
| - ); |
| 72 | +```php |
| 73 | +$postfields = array( |
| 74 | + 'screen_name' => 'usernameToBlock', |
| 75 | + 'skip_status' => '1' |
| 76 | +); |
| 77 | +``` |
68 | 78 |
|
69 | 79 | #### Perform the request! ####
|
70 | 80 |
|
71 |
| - $twitter = new TwitterAPIExchange($settings); |
72 |
| - echo $twitter->buildOauth($url, $requestMethod) |
73 |
| - ->setPostfields($postfields) |
74 |
| - ->performRequest(); |
| 81 | +```php |
| 82 | +$twitter = new TwitterAPIExchange($settings); |
| 83 | +echo $twitter->buildOauth($url, $requestMethod) |
| 84 | + ->setPostfields($postfields) |
| 85 | + ->performRequest(); |
| 86 | +``` |
75 | 87 |
|
76 | 88 | GET Request Example
|
77 |
| ----------------- |
| 89 | +------------------- |
78 | 90 |
|
79 | 91 | Set the GET field BEFORE calling buildOauth(); and everything else is the same:
|
80 | 92 |
|
81 |
| - $url = 'https://api.twitter.com/1.1/followers/ids.json'; |
82 |
| - $getfield = '?screen_name=J7mbo'; |
83 |
| - $requestMethod = 'GET'; |
| 93 | +```php |
| 94 | +$url = 'https://api.twitter.com/1.1/followers/ids.json'; |
| 95 | +$getfield = '?screen_name=J7mbo'; |
| 96 | +$requestMethod = 'GET'; |
84 | 97 |
|
85 |
| - $twitter = new TwitterAPIExchange($settings); |
86 |
| - echo $twitter->setGetfield($getfield) |
87 |
| - ->buildOauth($url, $requestMethod) |
88 |
| - ->performRequest(); |
| 98 | +$twitter = new TwitterAPIExchange($settings); |
| 99 | +echo $twitter->setGetfield($getfield) |
| 100 | + ->buildOauth($url, $requestMethod) |
| 101 | + ->performRequest(); |
| 102 | +``` |
89 | 103 |
|
90 | 104 | That is it! Really simple, works great with the 1.1 API. Thanks to @lackovic10 and @rivers on SO!
|
0 commit comments