我正试图从Twitter上嵌入推文.所以,我正在使用cURL来恢复json.我写了一点测试,但测试大约需要5秒钟,当我在本地运行时.所以,我不确定我在这里做错了什么.
public function get_tweet_embed($tw_id) {
$json_url = "https://api.twitter.com/1/statuses/oembed.json?id={$tw_id}&align=left&omit_script=true&hide_media=false";
$ch = curl_init( $json_url );
$start_time = microtime(TRUE);
$JSON = curl_exec($ch);
$end_time = microtime(TRUE);
echo $end_time - $start_time; //5.7961111068726
return $this->get_html($JSON);
}
private function get_html($embed_json) {
$JSON_Data = json_decode($embed_json,true);
$tw_embed_code = $JSON_Data["html"];
return $tw_embed_code;
}
Run Code Online (Sandbox Code Playgroud)
当我粘贴链接并从浏览器测试它时,它真的很快.