TwitterOAuth ile PHP’de uğraşırken her yerde çalışan kod yapısı bir türlü ajax.php ile veri aldığım yerde çalışmıyordu aldığım hata
Parse error: syntax error, unexpected 'use' (T_USE) in C:\xampp\htdocs\xxx\ajax.php on line 16
normalde kullandığım kod yapısı:
require 'autoload.php'; use Abraham\TwitterOAuth\TwitterOAuth; define('CONSUMER_KEY', 'gdfghfdhdhhdhfdhdfh'); // add your app consumer key between single quotes define('CONSUMER_SECRET', 'dhdfhdfhdfhdhfdhdfhdfhdfhdfhdhdfh'); // add your app consumer secret key between single quotes define('OAUTH_CALLBACK', 'http://localhost/xxxx/callback.php'); // your app callback URL i.e. $access_token = $_SESSION['access_token']; $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); $user = $connection->get("account/verify_credentials", ['include_email' => 'true']); // $user1 = $connection->get("https://api.twitter.com/1.1/account/verify_credentials.json", ['include_email' => true]);
Değişiklik yaptıktan sonra:
require 'autoload.php'; //use Abraham\TwitterOAuth\TwitterOAuth; define('CONSUMER_KEY', 'gdfghfdhdhhdhfdhdfh'); // add your app consumer key between single quotes define('CONSUMER_SECRET', 'dhdfhdfhdfhdhfdhdfhdfhdfhdfhdhdfh'); // add your app consumer secret key between single quotes define('OAUTH_CALLBACK', 'http://localhost/xxxx/callback.php'); // your app callback URL i.e. $access_token = $_SESSION['access_token']; $connection = new Abraham\TwitterOAuth\TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']); $user = $connection->get("account/verify_credentials", ['include_email' => 'true']); // $user1 = $connection->get("https://api.twitter.com/1.1/account/verify_credentials.json", ['include_email' => true]);
Görmüş olduğunuz gibi use Abraham\TwitterOAuth\TwitterOAuth; kullanımını iptal ettim ardından $connection değişkeni içerisine görülen değişiklikleri yaptım ve sorun çözüldü. Benzer hatayı farklı projede alanlar için de faydalı olması dileği ile iyi çalışmalar…