Posted By

jamesming on 12/14/09


Tagged

stream twitter tweet


Versions (?)

Who likes this?

10 people have marked this snippet as a favorite

wizard04
Zwendel
webalienz
mrgee
redstorm
alessio2
ninjacharlee
stamba
sbcjr
clac


tweet from php


 / Published in: PHP
 

URL: http://php.net/manual/en/function.stream-context-create.php

  1. <?php
  2. function tweet($message, $username, $password)
  3. {
  4. 'http' => array(
  5. 'method' => 'POST',
  6. 'header' => sprintf("Authorization: Basic %s
  7. ", base64_encode($username.':'.$password)).
  8. "Content-type: application/x-www-form-urlencoded
  9. ",
  10. 'content' => http_build_query(array('status' => $message)),
  11. 'timeout' => 5,
  12. ),
  13. ));
  14. $ret = file_get_contents('http://twitter.com/statuses/update.xml', false, $context);
  15.  
  16. return false !== $ret;
  17. }
  18. ?>
  19.  
  20. Pretty easy, no? Using the tweet() function is of course a piece of cake:
  21.  
  22. <?php
  23. tweet('From PHP, yeah...', 'fabpot', 'Pa$$');
  24. ?>

Report this snippet  

You need to login to post a comment.