我的服务器不支持 cURL。
我想通过 php 更新我的状态。
没有 cURL 怎么办?
再一次:没有 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
希望对您有所帮助。
如果您需要更多帮助,请告诉我,因为我自己就是一名 PHP 程序员。 谢谢
PK
关于php - Twitter Oauth 通过 PHP WITHOUT cURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3849415/