1
我試圖製作一個wordpress插件,通過API獲取twitter推文,並在頁面上插入短代碼[twitter]後在頁面上回應它們。Wordpress init_curl()函數錯誤
我得到一個錯誤:
"FATAL ERROR: CALL TO UNDEFINED FUNCTION CURL_INIT() IN C:\WAMP\WWW\WP\WP-CONTENT\PLUGINS\PLOG\PLUGIN.PHP ON LINE 45"
有代碼既沒有語法錯誤,在那兒任何邏輯上的錯誤。
下面是代碼:
<?php
/* Plugin Name: Testing a Plugin
* Plugin URI: http://www.wordpress.com
* Description: Just Testing out a plugin.
* Author: Knooww
* Author URI: http://www.wordpress.com
*/
?>
<?php
//limit calls to API..
// Save data in cache, refresh content after an hour
add_shortcode('twitter', function ($atts,$content){
$atts = shortcode_atts(array('username'=>'Default-Username',
'content' =>!empty($content) ? $content:'Follow me on twitter',
'show_tweets'=>'false',
'tweet_reset_time'=>10, //time to refresh fetch of tweets
'num_tweets'=>5
),$atts);
extract($atts);
if($show_tweets){
$tweets = fetch_tweets($num_tweets,$username,$tweet_reset_time);
}
//return '<a href="http://www.twitter.com/'.$username.'">'.$content.'</a>';
});// end add_shortcode
function fetch_tweets($num_tweets,$username,$tweet_reset_time){
$tweets = curl("https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name='$username'&count=2");
print_r($tweets);
}
function curl($url){
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($c, CURLOPT_TIMEOUT, 5);
return json_decode(curl_exec($c));
}
?>
請讓我知道我錯過了什麼。
上窗戶