Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- $username = 'username';
- $password= 'WHATEVER';
- $message='YOUR NEW STATUS';
- function tweet($message, $username, $password)
- {
- $context = stream_context_create(array(
- 'http' => array(
- 'method' => 'POST',
- 'header' => sprintf("Authorization: Basic %srn", base64_encode($username.':'.$password)).
- "Content-type: application/x-www-form-urlencodedrn",
- 'content' => http_build_query(array('status' => $message)),
- 'timeout' => 5,
- ),
- ));
- $ret = file_get_contents('http://twitter.com/statuses/update.xml', false, $context);
- return false !== $ret;
- }
- echo tweet($message, $username, $password);
- ?>
- <?php
- $username = 'username';
- $password= 'WHATEVER';
- $message='YOUR NEW STATUS';
- $out="POST http://twitter.com/statuses/update.json HTTP/1.1rn"
- ."Host: twitter.comrn"
- ."Authorization: Basic ".base64_encode ("$username:$password")."rn"
- ."Content-type: application/x-www-form-urlencodedrn"
- ."Content-length: ".strlen ("status=$message")."rn"
- ."Connection: Closernrn"
- ."status=$msg";
- $fp = fsockopen ('twitter.com', 80);
- fwrite ($fp, $out);
- fclose ($fp);
- ?>
- <?php
- /*
- * using file_get_contents
- */
- $key = '';
- $secret = '';
- $api_endpoint = 'https://api.twitter.com/1.1/search/tweets.json?q=news'; // endpoint must support "Application-only authentication"
- // request token
- $basic_credentials = base64_encode($key.':'.$secret);
- $opts = array('http' =>
- array(
- 'method' => 'POST',
- 'header' => 'Authorization: Basic '.$basic_credentials."rn".
- "Content-type: application/x-www-form-urlencoded;charset=UTF-8rn",
- 'content' => 'grant_type=client_credentials'
- )
- );
- $context = stream_context_create($opts);
- // send request
- $pre_token = file_get_contents('https://api.twitter.com/oauth2/token', false, $context);
- $token = json_decode($pre_token, true);
- if (isset($token["token_type"]) && $token["token_type"] == "bearer"){
- $opts = array('http' =>
- array(
- 'method' => 'GET',
- 'header' => 'Authorization: Bearer '.$token["access_token"]
- )
- );
- $context = stream_context_create($opts);
- $data = file_get_contents($api_endpoint, false, $context);
- print $data;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement