Bonjour,
Voila je rencontre un petit problème avec mon code.
Décrivez ici votre code ou ce que vous cherchez à faire
<?php
use Abraham\TwitterOAuth\TwitterOAuth;
class Twitter {
private $consumer_key;
private $consumer_secret;
private $cache;
public function __construct($consumer_key, $consumer_secret, $cache){
$this->consumer_key = $consumer_key;
$this->consumer_secret = $consumer_secret;
$this->cache = $cache;
}
private function getAppAccessToken(){
$oauth = new TwitterOAuth($this->consumer_key, $this->consumer_secret);
$accessToken = $oauth->oauth2('oauth2/token', ['grant_type' => 'client_credentials']);
return $accessToken->access_token;
}
public function lastTweets($screen_name, $limit = 3) {
if(time() - filemtime($this->cache) > 60) {
$twitter = new TwitterOAuth($this->consumer_key,$this->consumer_secret , null, $this->getAppAccessToken());
$tweets = $twitter->get('statuses/user_timeline', ['screen_name' => $screen_name,
'exclude_replies' => true,
'count' =>3]);
file_put_contents($this->cache, serialize($tweets));
} else {
$tweets = unserialize(file_get_contents($this->cache));
}
return array_slice($tweets, 0, $limit);
}
}
?>
Je cherche simplement à résoudre le message d'erreur.
Warning: filemtime(): stat failed for /Applications/XAMPP/xamppfiles/htdocs/port/includes/cache/tweets.tmp in /Applications/XAMPP/xamppfiles/htdocs/port/class/Twitter.php on line 30
Warning: file_put_contents(/Applications/XAMPP/xamppfiles/htdocs/port/includes/cache/tweets.tmp): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/port/class/Twitter.php on line 38
Je ne comprends pas ces erreurs, car, par définition, le fichier de cache n'existe pas avant le premier chargement de page.
Des idées ? merci et à bientôt :).