Last active
December 21, 2015 23:18
-
-
Save ScreamingDev/6381121 to your computer and use it in GitHub Desktop.
get user timeline in twitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once __DIR__ . DIRECTORY_SEPARATOR . 'twitter.php'; | |
| $t = new twitter(); | |
| // https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline | |
| $responseArray = $t->gimme( | |
| '1.1/statuses/user_timeline', | |
| array( | |
| 'screen_name' => 'HalloPHPWelt' | |
| ) | |
| ); | |
| echo "Fetched " . count($responseArray) . " posts." . PHP_EOL; | |
| $first = current($responseArray); | |
| print_r(array_keys($first)); | |
| echo PHP_EOL . $first['text'] . PHP_EOL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once __DIR__ . DIRECTORY_SEPARATOR . 'tmhOAuth.php'; | |
| class twitter extends tmhOAuth | |
| { | |
| public function __construct($config = array()) | |
| { | |
| $this->config = array_merge( | |
| array( | |
| // change the values below to ones for your application | |
| 'consumer_key' => 'CHANGE_THIS', | |
| 'consumer_secret' => 'CHANGE_THIS', | |
| 'token' => 'CHANGE_THIS', | |
| 'secret' => 'CHANGE_THIS', | |
| // 'bearer' => 'YOUR_OAUTH2_TOKEN', // what's that for? | |
| 'user_agent' => 'tmhOAuth ' . parent::VERSION . ' Examples 0.1', | |
| 'curl_ssl_verifypeer' => false, // just in case cacert.pm is not given | |
| ), | |
| $config | |
| ); | |
| parent::__construct($this->config); | |
| } | |
| /** | |
| * Just do it FFS! | |
| * | |
| * @param $target URL https://dev.twitter.com/docs/api/1.1 | |
| * @param $args See doc | |
| * @param string $method | |
| * @return array|mixed | |
| */ | |
| function gimme($target, $args, $method = 'GET') | |
| { | |
| $url = $this->url($target); | |
| $this->request($method, $url, $args); | |
| return json_decode($this->response['response'], true); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment