Advertisement
Guest User

Untitled

a guest
Nov 30th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. <?php
  2. set_time_limit(0);
  3. $username = 'username';
  4. $password= 'WHATEVER';
  5. $message='YOUR NEW STATUS';
  6. function tweet($message, $username, $password)
  7. {
  8. $context = stream_context_create(array(
  9. 'http' => array(
  10. 'method' => 'POST',
  11. 'header' => sprintf("Authorization: Basic %srn", base64_encode($username.':'.$password)).
  12. "Content-type: application/x-www-form-urlencodedrn",
  13. 'content' => http_build_query(array('status' => $message)),
  14. 'timeout' => 5,
  15. ),
  16. ));
  17. $ret = file_get_contents('http://twitter.com/statuses/update.xml', false, $context);
  18. return false !== $ret;
  19. }
  20. echo tweet($message, $username, $password);
  21. ?>
  22.  
  23. <?php
  24.  
  25.  
  26.  
  27. $username = 'username';
  28.  
  29. $password= 'WHATEVER';
  30.  
  31. $message='YOUR NEW STATUS';
  32.  
  33.  
  34.  
  35. $out="POST http://twitter.com/statuses/update.json HTTP/1.1rn"
  36.  
  37. ."Host: twitter.comrn"
  38.  
  39. ."Authorization: Basic ".base64_encode ("$username:$password")."rn"
  40.  
  41. ."Content-type: application/x-www-form-urlencodedrn"
  42.  
  43. ."Content-length: ".strlen ("status=$message")."rn"
  44.  
  45. ."Connection: Closernrn"
  46.  
  47. ."status=$msg";
  48.  
  49.  
  50.  
  51. $fp = fsockopen ('twitter.com', 80);
  52.  
  53. fwrite ($fp, $out);
  54.  
  55. fclose ($fp);
  56.  
  57. ?>
  58.  
  59. <?php
  60. /*
  61. * using file_get_contents
  62. */
  63.  
  64. $key = '';
  65. $secret = '';
  66. $api_endpoint = 'https://api.twitter.com/1.1/search/tweets.json?q=news'; // endpoint must support "Application-only authentication"
  67.  
  68. // request token
  69. $basic_credentials = base64_encode($key.':'.$secret);
  70. $opts = array('http' =>
  71. array(
  72. 'method' => 'POST',
  73. 'header' => 'Authorization: Basic '.$basic_credentials."rn".
  74. "Content-type: application/x-www-form-urlencoded;charset=UTF-8rn",
  75. 'content' => 'grant_type=client_credentials'
  76. )
  77. );
  78.  
  79. $context = stream_context_create($opts);
  80.  
  81. // send request
  82. $pre_token = file_get_contents('https://api.twitter.com/oauth2/token', false, $context);
  83.  
  84. $token = json_decode($pre_token, true);
  85.  
  86. if (isset($token["token_type"]) && $token["token_type"] == "bearer"){
  87. $opts = array('http' =>
  88. array(
  89. 'method' => 'GET',
  90. 'header' => 'Authorization: Bearer '.$token["access_token"]
  91. )
  92. );
  93.  
  94. $context = stream_context_create($opts);
  95.  
  96. $data = file_get_contents($api_endpoint, false, $context);
  97.  
  98. print $data;
  99. }
  100. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement