<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//Include Composer's autoloader
include 'vendor/autoload.php';
public function test_auth() {
try{
$hybridauth = new HybridauthHybridauth($config);
//Attempt to authenticate users with a provider by name
$adapter = $hybridauth->authenticate('Twitter');
//Returns a boolean of whether the user is connected with Twitter
$isConnected = $adapter->isConnected();
//Retrieve the user's profile
$userProfile = $adapter->getUserProfile();
//Inspect profile's public attributes
var_dump($userProfile);
//Disconnect the adapter
$adapter->disconnect();
}
catch(Exception $e){
echo 'Oops, we ran into an issue! ' . $e->getMessage();
}
}
遇到未捕获的异常
类型:错误
消息:未找到类"混合身份验证\混合身份验证\混合身份验证">
文件名: C:\xampp\htdocs\paymatrix_v2\application\controllers\Hauth.php
行号:35
回溯:
文件: C:\xampp\htdocs\paymatrix_v2\index.php行: 294功能:require_once
作曲家.json 文件
{
"description": "The CodeIgniter framework",
"name": "codeigniter/framework",
"type": "project",
"homepage": "https://codeigniter.com",
"license": "MIT",
"support": {
"forum": "http://forum.codeigniter.com/",
"wiki": "https://github.com/bcit-ci/CodeIgniter/wiki",
"irc": "irc://irc.freenode.net/codeigniter",
"source": "https://github.com/bcit-ci/CodeIgniter"
},
"require": {
"php": ">=5.2.4",
"mailgun/mailgun-php": "^2.1",
"php-http/curl-client": "^1.6",
"guzzlehttp/psr7": "^1.3",
"aws/aws-sdk-php": "3.*",
"pipl/piplapis-php" : "^5.0",
"hybridauth/hybridauth": "^2.9"
},
"require-dev": {
"mikey179/vfsStream": "1.1.*",
"aws/aws-sdk-php": "dev-master"
},
"autoload": {
"classmap": ["vendor/pipl/piplapis-php/src","vendor/pipl/"]
}
}
自动加载.php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit9da23362304113093d59b5cbcc0e2b35::getLoader();
混合身份验证位置
vendor/hybridauth/hybridauth/
此文件已包含在代码点火器核心文件中。 无需再次包含在您的类文件中
include 'vendor/autoload.php';
在您的函数内
public function test_auth() {
// Before code
$config = [
'callback' => 'https://example.com/path/to/script.php',
'keys' => [ 'key' => 'your-twitter-consumer-key', 'secret' => 'your-twitter-consumer-secret' ]
];
try {
$twitter = new HybridauthProviderTwitter($config);
$twitter->authenticate();
$accessToken = $twitter->getAccessToken();
$userProfile = $twitter->getUserProfile();
$apiResponse = $twitter->apiRequest( 'statuses/home_timeline.json' );
}
catch(Exception $e){
echo 'Oops, we ran into an issue! ' . $e->getMessage();
}
}
从软件包自述文件中检查使用情况
https://github.com/hybridauth/hybridauth
我也遇到了同样的问题。当我在根位置使用作曲家安装软件包时,它仍然说找不到第三方类。所以这是我的解决方案。首先,我将"composer_autoload"配置更改为 TRUE。
$config['composer_autoload'] = 真;
默认情况下,更改上述配置后,在APPPATH(应用程序文件夹(下查找供应商/自动加载文件是不正确的。所以我将常量更改为 FCPATH(根路径(,因为根是使用作曲家安装第三方软件包的正确路径。
更改自系统/内核/点火器.php:165
if ($composer_autoload === TRUE)
{
file_exists(APPPATH.'vendor/autoload.php')
? require_once(APPPATH.'vendor/autoload.php')
: log_message('error', '$config['composer_autoload'] is set to TRUE but '.APPPATH.'vendor/autoload.php was not found.');
}
自
if ($composer_autoload === TRUE)
{
file_exists(FCPATH.'vendor/autoload.php')
? require_once(FCPATH.'vendor/autoload.php')
: log_message('error', '$config['composer_autoload'] is set to TRUE but '.FCPATH.'vendor/autoload.php was not found.');
}
最后,运行
作曲家转储自动加载
万一仍然不工作。快乐编码!!