
自作のツイッターアプリを自分のアカウントで認証しようとしています。
ライブラリはAbraham\TwitterOAuthを使っています。
common.php
php
1<?php 2define('CONSUMER_KEY', 'xxxxxxxxxxx'); 3define('CONSUMER_SECRET', 'xxxxxxxxxxx'); 4define('OAUTH_CALLBACK', 'http://ryota01.com/twitter/callback.php');
login.php
php
1<?php 2if (!isset($_SESSION)) { 3 session_start(); 4} 5 6require_once("common.php"); 7require_once("http://example/twitter/vendor/abraham/twitteroauth/autoload.php"); 8use Abraham\TwitterOAuth\TwitterOAuth; 9 10$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET); 11 12 13$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK)); 14//var_dump($request_token); 15 16$_SESSION['oauth_token'] = $request_token['oauth_token']; 17$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; 18//var_dump($_SESSION); 19 20$url = $connection->url('oauth/authenticate', array('oauth_token' => $request_token['oauth_token'])); 21 22//echo session_id()."<br>"; 23var_dump($_SERVER); 24header("location: ".$url); 25
twitter/vendor/abraham/twitteroauth/autoload.php
php
1<?php 2 3/** 4 * Use to autoload needed classes without Composer. 5 * 6 * @param string $class The fully-qualified class name. 7 * @return void 8 */ 9 10spl_autoload_register(function ($class) { 11 echo "inner str"; 12 13 // project-specific namespace prefix 14 $prefix = 'Abraham\TwitterOAuth\'; 15 16 // base directory for the namespace prefix 17 $base_dir = __DIR__ . '/src/'; 18 19 // does the class use the namespace prefix? 20 $len = strlen($prefix); 21 if (strncmp($prefix, $class, $len) !== 0) { 22 // no, move to the next registered autoloader 23 return; 24 } 25 26 // get the relative class name 27 $relative_class = substr($class, $len); 28 var_dump($relative_class); 29 var_dump(__DIR__); 30 31 // replace the namespace prefix with the base directory, replace namespace 32 // separators with directory separators in the relative class name, append 33 // with .php 34 $file = $base_dir . str_replace('\', '/', $relative_class) . '.php'; 35 36 // if the file exists, require it 37 if (file_exists($file)) { 38 require $file; 39 } 40 41});
login.phpの出力は
Fatal error: Uncaught Error: Class 'Abraham\TwitterOAuth\TwitterOAuth' not found in /twitter/login.php:10 Stack trace: #0 {main} thrown in /twitter/login.php on line 10
でした。
$connection = new TwitterOAuth()の時点でspl_autoload_register()に登録された関数が読まれるはずですが、echo "inner str";は読まれていないようです。
なぜですか?




回答1件
あなたの回答
tips
プレビュー