Twitter API 1.1问题

时间:2013-06-13 15:01:11

标签: php twitter

今天,我工作场所的一位开发人员告诉我,由于版本1.0在昨天被弃用,我们的Joomla Twitter API模块已不再有效。

我在过去几个小时里一直在努力让新的API功能正常工作,但我似乎无法在任何地方找到它,这让我发疯。

我正在利用tmhOAutho.php(https://github.com/themattharris/tmhOAuth)库试图完成我需要的工作。 我需要做的只是从一个Twitter帐户中获取推文,但现在这样做似乎要困难得多。

到目前为止,我有:

include('tmhOAuth.php');
        include('tmhUtilities.php');

        $tmhOAuth = new tmhOAuth(array(
          'consumer_key'    => '"removed"',
          'consumer_secret' => '"removed"',
          'user_token'      => '"removed"',
          'user_secret'     => '"removed"',
        ));

        $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array(
          'screen_name' => 'ActiveSoton'));
        return $response = $tmhOAuth;

我确实从上面得到了回复,但它不是时间推文的推文,它是以下内容:

mhOAuth Object ( [response] => Array ( [raw] => [code] => 0 [response] => [info] => Array ( [url] => https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=ActiveSoton [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.096441 [namelookup_time] => 0.001874 [connect_time] => 0.096464 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ( ) [redirect_url] => ) [error] => error setting certificate verify locations: CAfile: /home/activeso/public_html/templates/protostar/cacert.pem CApath: /home/activeso/public_html/templates/protostar [errno] => 77 ) [params] => Array ( ) [headers] => Array ( [Authorization] => OAuth oauth_consumer_key="lVuRW7mPeW3v3Xv0CLzg", oauth_nonce="bd2ddb198ab19c7060b0fa23693c34b0", oauth_signature="J5AR853KRdhkSeQeGno1%2FhjcjFQ%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1371134884", oauth_token="19649542-2g5Zh9bdi5eVetJlQMu9bUi5NeCmR7VFLFawXatfl", oauth_version="1.0" ) [auto_fixed_time] => [buffer] => [config] => Array ( [user_agent] => tmhOAuth 0.7.5+SSL - //github.com/themattharris/tmhOAuth [timezone] => UTC [use_ssl] => 1 [host] => api.twitter.com [consumer_key] => lVuRW7mPeW3v3Xv0CLzg [consumer_secret] => omaQwbQCzcj8tNp2FGIgVUKZel9PZisfVm2ZJSnA [user_token] => 19649542-2g5Zh9bdi5eVetJlQMu9bUi5NeCmR7VFLFawXatfl [user_secret] => Pw8MNNbtplfR51hlw3BQZ7VfHPAskZ65n0P2A0fbmQ [force_nonce] => [nonce] => bd2ddb198ab19c7060b0fa23693c34b0 [force_timestamp] => [timestamp] => 1371134884 [oauth_version] => 1.0 [oauth_signature_method] => HMAC-SHA1 [curl_connecttimeout] => 30 [curl_timeout] => 10 [curl_ssl_verifyhost] => 2 [curl_ssl_verifypeer] => 1 [curl_cainfo] => /home/activeso/public_html/templates/protostar/cacert.pem [curl_capath] => /home/activeso/public_html/templates/protostar [curl_followlocation] => [curl_proxy] => [curl_proxyuserpwd] => [curl_encoding] => [is_streaming] => [streaming_eol] => [streaming_metrics_interval] => 60 [as_header] => 1 [debug] => [multipart] => ) [custom_headers] => Array ( ) [method] => GET [url] => https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=ActiveSoton [signing_params] => oauth_consumer_key=lVuRW7mPeW3v3Xv0CLzg&oauth_nonce=bd2ddb198ab19c7060b0fa23693c34b0&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1371134884&oauth_token=19649542-2g5Zh9bdi5eVetJlQMu9bUi5NeCmR7VFLFawXatfl&oauth_version=1.0&screen_name=ActiveSoton [auth_params] => Array ( [oauth_consumer_key] => lVuRW7mPeW3v3Xv0CLzg [oauth_nonce] => bd2ddb198ab19c7060b0fa23693c34b0 [oauth_signature] => J5AR853KRdhkSeQeGno1%2FhjcjFQ%3D [oauth_signature_method] => HMAC-SHA1 [oauth_timestamp] => 1371134884 [oauth_token] => 19649542-2g5Zh9bdi5eVetJlQMu9bUi5NeCmR7VFLFawXatfl [oauth_version] => 1.0 ) [request_params] => Array ( ) [base_string] => GET&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fuser_timeline.json&oauth_consumer_key%3DlVuRW7mPeW3v3Xv0CLzg%26oauth_nonce%3Dbd2ddb198ab19c7060b0fa23693c34b0%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1371134884%26oauth_token%3D19649542-2g5Zh9bdi5eVetJlQMu9bUi5NeCmR7VFLFawXatfl%26oauth_version%3D1.0%26screen_name%3DActiveSoton [signing_key] => omaQwbQCzcj8tNp2FGIgVUKZel9PZisfVm2ZJSnA&Pw8MNNbtplfR51hlw3BQZ7VfHPAskZ65n0P2A0fbmQ [auth_header] => OAuth oauth_consumer_key="lVuRW7mPeW3v3Xv0CLzg", oauth_nonce="bd2ddb198ab19c7060b0fa23693c34b0", oauth_signature="J5AR853KRdhkSeQeGno1%2FhjcjFQ%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1371134884", oauth_token="19649542-2g5Zh9bdi5eVetJlQMu9bUi5NeCmR7VFLFawXatfl", oauth_version="1.0" ) 1

有谁知道如何或能够指出我如何获得时间轴推文的正确方向? 谢谢!

1 个答案:

答案 0 :(得分:0)

要显示推文,请使用以下代码:

<?php 
$response_objects = json_decode($tmhOAuth->response['response']); 

foreach($response_objects as $tweet) {

echo $tweet->text, '<br>'; 

}; 
?>