现在我使用这段代码从twitter获取流,它工作得很好。但是很快,使用用户和密码的基本验证将被弃用,我如何使用oauth发送此请求?
$fp = fsockopen("ssl://stream.twitter.com", 443, $errno, $errstr, 30);
if (!$fp)
{
echo "ERROR: Twitter Stream Error: failed to open socket";
} else
{
$request = "GET /1.1/statuses/filter.json?track=";
$request .= urlencode(implode($_keywords, ',')) . " HTTP/1.1'r'n";
$request .= "Host: stream.twitter.com'r'n";
$request .= "Authorization: Basic ";
$request .= base64_encode($this->m_username . ':' . $this->m_password);
$request .= "'r'n'r'n";
您可以使用像tmhOAuth这样的东西来轻松实现这样的功能。
在这里找到库:https://github.com/themattharris/tmhOAuth
一个使用filter.json的例子:https://github.com/themattharris/tmhOAuth-examples/blob/master/streaming.php
您还需要一个应用程序,注册/登录(使用您的正常twitter帐户),并创建一个通过:https://dev.twitter.com