微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Twitter Oauth通过PHP没有cURL

我的服务器不支持cURL.

我想通过PHP更新我的状态.

没有cURL怎么做?

再次:没有卷曲!

解决方法:

以下是如何在不使用cURL和PHP的情况下发送推文.
我们有两个选择 –

使用流上下文

PHP函数stream_context_create具有魔力.它使用传递的任何选项创建并返回流上下文.

<?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 %s\r\n", base64_encode($username.':'.$password)).
                   "Content-type: application/x-www-form-urlencoded\r\n",
      '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一个非常强大的套接字编程API.这些套接函数几乎包含了基于套接字的客户端 – 服务器通过TCP / IP进行通信所需的一切. fsockopen打开Internet或Unix域套接字连接.

<?PHP



$username = 'username';

$password= 'WHATEVER';

$message='YOUR NEW STATUS';



$out="POST http://twitter.com/statuses/update.json HTTP/1.1\r\n"

  ."Host: twitter.com\r\n"

  ."Authorization: Basic ".base64_encode ("$username:$password")."\r\n"

  ."Content-type: application/x-www-form-urlencoded\r\n"

  ."Content-length: ".strlen ("status=$message")."\r\n"

  ."Connection: Close\r\n\r\n"

  ."status=$msg";



$fp = fsockopen ('twitter.com', 80);

fwrite ($fp, $out);

fclose ($fp); 

?>

取自这里:http://www.motyar.info/2010/02/update-twitter-status-with-php-nocurl.html

希望htis有所帮助.

如果您需要更多帮助,请告诉我,因为我自己是一名PHP程序员.
谢谢

PK

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐