问题描述
我已经在我的网站上使用了这个插件来显示推文,但即使是插件网站也有问题:
http://coda.co.za/content/projects/jquery.twitter/
代码:
<pre class="代码">jQuery(函数($){$("#twitter").tweet({join_text: "自动",用户名:Jquery",avatar_size: 48,数:4,auto_join_text_default: "",auto_join_text_ed: "",auto_join_text_ing: "",auto_join_text_reply: "",auto_join_text_url: "",loading_text: "正在加载推文..."});});<div id="twitter"></div>
每个第三方插件(我认为)都不再工作了.我也见过:
那么,替代品是什么?
如果您访问了上面的链接,您可能已经了解问题出在哪里.
解决方案 由于 twitter 已从非认证 1.0
API 更改为 OAuth 1.1
,您现在必须代理如果您想使用该插件,请通过
这是代理请求的 twitter-proxy.,并更新 oauth_access_token、oauth_access_token_secret、consumer_key 的值>、consumer_secret 和 screen_name 以反映您自己的 Twitter 帐户.
如果您需要创建应用程序,请访问 https://dev.twitter.com/apps获取这些值.
'从推特上获取','oauth_access_token_secret' =>'从推特上获取','consumer_key' =>'从推特上获取','consumer_secret' =>'从推特上获取','base_url' =>'https://api.twitter.com/1.1/',//请求特定用户'screen_name' =>'your_twitter_screenname','计数' =>3);$twitter_request = 'statuses/user_timeline.json?screen_name='.$config['screen_name'].'&count='.$config['count'];//将 $twitter_request 解析为 URL 参数$url_part = parse_url($twitter_request);/* url_arguments=* 大批* (* [屏幕名称] =>切罗内* [计数] =>3* )*/parse_str($url_part['query'], $url_arguments);$base_url = $config['base_url'].$url_part['path'];$full_url = $config['base_url'].$twitter_request;//设置OAuth授权数组$oauth = 数组('oauth_consumer_key' =>$config['consumer_key'],'oauth_nonce' =>时间(),'oauth_signature_method' =>'HMAC-SHA1','oauth_token' =>$config['oauth_access_token'],'oauth_timestamp' =>时间(),'oauth_version' =>'1.0');//为请求构建向量$composite_request = _BaseString($base_url, 'GET', array_merge($oauth, $url_arguments));$composite_key = rawurlencode($config['consumer_secret']).'&'.rawurlencode($config['oauth_access_token_secret']);$oauth_signature = base64_encode(hash_hmac('sha1', $composite_request, $composite_key, true));$oauth['oauth_signature'] = $oauth_signature;//发出卷曲请求$options = 数组(CURLOPT_HTTPHEADER =>数组(_AuthorizationHeader($oauth),'Expect:'),CURLOPT_HEADER =>错误的,CURLOPT_URL =>$full_url,CURLOPT_RETURNTRANSFER =>真的,CURLOPT_SSL_VERIFYPEER =>错误的);$feed = curl_init();curl_setopt_array($feed, $options);$result = curl_exec($feed);$info = curl_getinfo($feed);curl_close($feed);//向最终用户发送合适的标头.if(isset($info['content_type']) &&isset($info['size_download'])){header('Content-Type: '.$info['content_type']);header('Content-Length: '.$info['size_download']);}退出($结果);函数_BaseString($base_url, $method, $values) {$ret = 数组();ksort($values);foreach($values as $key=>$value)$ret[] = $key."=".rawurlencode($value);return $method."&".rawurlencode($base_url).'&'.rawurlencode(implode('&', $ret));}函数 _AuthorizationHeader($oauth) {$ret = '授权:OAuth ';$values = array();foreach($oauth as $key=>$value)$values[] = $key.'="'.rawurlencode($value).'"';$ret .= implode(', ', $values);返回 $ret;}?>
现在将 jquery.tweets.js
文件中现有的 build_api_url
函数替换为以下函数,确保替换 yoursite.com
function build_api_url() {var proto = ('https:' == document.location.protocol ? 'https:' : 'http:');var count = (s.fetch === null) ?s.count : s.fetch;var common_params = '&callback=?';如果(s.list){返回 'http://yoursite.com/twitter-proxy.
2014 年 12 月 17 日更新:截至 2014 年 2 月 27 日,Twitter 需要使用 SSL 连接到其 API 服务器.我已更新代码以反映这一点.
I have used this plugin on my website to display tweets, but even the plugin site has the problem:
http://coda.co.za/content/projects/jquery.twitter/
Code:
<div class="columns">
<pre class="code">
jQuery(function($){
$("#twitter").tweet({
join_text: "auto",
username: "Jquery",
avatar_size: 48,
count: 4,
auto_join_text_default: "",
auto_join_text_ed: "",
auto_join_text_ing: "",
auto_join_text_reply: "",
auto_join_text_url: "",
loading_text: "loading tweets..."
});
});
</pre>
<div id="twitter"></div>
Every third party plug-in (I think) is not working any more. I have seen also:
So, what would be the replacement?
If you have visited the links above you might have understood, where is the problem.
解决方案 Since twitter has changed from non authenticated 1.0
API to OAuth 1.1
, you now have to proxy the API request through
Here's the twitter-proxy. in your site, and update the values of oauth_access_token, oauth_access_token_secret, consumer_key, consumer_secret and screen_name to reflect your own Twitter account.
Visit https://dev.twitter.com/apps if you need to create an application to get these values.
<?
Now replace the existing build_api_url
function in your jquery.tweets.js
file with the function below, making sure you replace yoursite.com
function build_api_url() {
var proto = ('https:' == document.location.protocol ? 'https:' : 'http:');
var count = (s.fetch === null) ? s.count : s.fetch;
var common_params = '&callback=?';
if (s.list) {
return 'http://yoursite.com/twitter-proxy.
Update 2014-12-17: As of 2014-02-27, Twitter requires the use of SSL to connect to its API servers. I have updated the code to reflect this.
这篇关于jquery.tweet.js 插件不起作用,如何显示推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-27 21:57