2012-06-27 2 views
0

Я использую hybridauth, чтобы получить информацию от социальных веб-сайтов, таких как facebook, twitter и т. Д. PHP lib to connect i настроен с использованием install.php, который доступен в самой папке hybridauth.Как решить эту «ошибку конфигурации Hybriauth»?

, когда я пытался использовать некоторые примеры, доступные в моем приложении я получаю следующую ошибку

Hybriauth configuration error. 

Original error message: Hybriauth config does not exist on the given path. 

здесь мой полный код: (index.php)

<?php 
    // start a new session (required for Hybridauth) 
    session_start(); 

    // change the following paths if necessary 

    //require_once(str_replace('//','/',dirname(__FILE__).'/') .'folder/sub.php'); 

    $config = dirname(__FILE__).'hybridauth/config.php'; 
    require_once("hybridauth/Hybrid/Auth.php"); 
    try{ 
    // create an instance for Hybridauth with the configuration file path as parameter 
    $hybridauth = new Hybrid_Auth($config); 
    // try to authenticate the user with twitter, 
    // user will be redirected to Twitter for authentication, 
    // if he already did, then Hybridauth will ignore this step and return an instance of the adapter 
    $twitter = $hybridauth->authenticate("Twitter"); 

    // get the user profile 
    $twitter_user_profile = $twitter->getUserProfile(); 
    echo "Ohai there! U are connected with: <b>{$twitter->id}</b><br />"; 
    echo "As: <b>{$twitter_user_profile->displayName}</b><br />"; 
    echo "And your provider user identifier is: <b>{$twitter_user_profile->identifier}</b><br />"; 

    // debug the user profile 
    print_r($twitter_user_profile); 

    // exp of using the twitter social api: return users count of friends, followers, updates etc. 
    $account_totals = $twitter->api()->get('account/totals.json'); 

    // print recived stats 
    echo "Here some of yours stats on twitter: " . print_r($account_totals, true); 

    // disconnect the user ONLY form twitter 
    // this will not disconnect the user from others providers if any used nor from your application 
    echo "Logging out.."; 
    $twitter->logout(); 
    } 
    catch(Exception $e){ 
    // Display the recived error, 
    // to know more please refer to Exceptions handling section on the userguide 
    switch($e->getCode()){ 
    case 0 : echo "Unspecified error."; break; 
    case 1 : echo "Hybriauth configuration error."; break; 
    case 2 : echo "Provider not properly configured."; break; 
    case 3 : echo "Unknown or disabled provider."; break; 
    case 4 : echo "Missing provider application credentials."; break; 
    case 5 : echo "Authentification failed. " 
    . "The user has canceled the authentication or the provider refused the connection."; 
    break; 
    case 6 : echo "User profile request failed. Most likely the user is not connected " 
    . "to the provider and he should authenticate again."; 
    $twitter->logout(); 
    break; 
    case 7 : echo "User not connected to the provider."; 
    $twitter->logout(); 
    break; 
    case 8 : echo "Provider does not support this feature."; break; 
    } 

    // well, basically your should not display this to the end user, just give him a hint and move on.. 
    echo "<br /><br /><b>Original error message:</b> " . $e->getMessage(); 
    } 

моя структура папок следующим образом:

project folder : 
slingshare 
    --hybridauth 
     -- Hybrid 
      --Auth.php 
    --config.php 
index.php 

, так как я очень новый парень в этом PHP я не могу найти это, пожалуйста, помогите мне найти это.

С уважением Тони

ответ

4

dirname даст вам что-то вроде /my/website/scripts без концовки слэш.

так что вы должны изменить свой код:

$config = dirname(__FILE__).'/hybridauth/config.php'; 

в сторону, рассмотреть возможность использования абсолютных путей для вашего требуют() s и включают в себя() s

+0

спасибо это помогло мне – SAR

+0

Нет Probs Тони, добро пожаловать на PHP: P это произойдет много. –

Смежные вопросы