【问题标题】:Joomla - Getting parameter into external fileJoomla - 将参数输入外部文件
【发布时间】:2016-04-18 02:15:53
【问题描述】:

我正在尝试在模块中嵌入 vimeo 视频播放列表脚本,但在获取 $token 参数时遇到问题。

这是我使用官方 php 库获取 vimeo 密钥、秘密和令牌的文件:https://github.com/vimeo/vimeo.php

outside-web-root-settings.php:

define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../..' ));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$user =& JFactory::getUser();
$session =& JFactory::getSession();

jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mod_module');
$moduleParams = new JRegistry();
$moduleParams->loadString($module->params);
    $vkey = $moduleParams->get('vimkey'); 
    $vsecret = $moduleParams->get('vimsecret'); 
    $vtoken = $moduleParams->get('vimtoken'); 

    $key = '$vkey'; 
    $secret = '$vsecret';
    $token = '$vtoken';

脚本正确获取$vkey$vsecret 参数,但没有正确获取$vtoken。我在控制台上收到此错误:

您必须提供经过身份验证的有效访问令牌。

我为 $vtoken 的 var_dump 得到这个

string(32) "3wsrsdf234mytoken2342werwr"

但是当我将参数 $token 更改为:

$token = '3wsrsdf234mytoken2342werwr';

然后脚本正常工作。我该如何解决这个问题?


vimeo_data.php

require_once("../../outside-web-root-settings.php");

if(!isset($_REQUEST['type']) || !isset($_REQUEST['page']) || !isset($_REQUEST['per_page']) || IsNullOrEmpty($key) || IsNullOrEmpty($secret) || IsNullOrEmpty($token)) exit("PHP Vimeo information missing!");

function IsNullOrEmpty($v){
    return (!isset($v) || trim($v)==='');
}

$type = $_REQUEST['type'];
$page = $_REQUEST['page'];
$per_page = $_REQUEST['per_page'];
$path = isset($_REQUEST['path']) && !IsNullOrEmpty($_REQUEST['path']) ? $_REQUEST['path'] : null;
$user = isset($_REQUEST['user']) && !IsNullOrEmpty($_REQUEST['user']) ? $_REQUEST['user'] : null;
$query = isset($_REQUEST['query']) && !IsNullOrEmpty($_REQUEST['query']) ? $_REQUEST['query'] : null;
$sort = isset($_REQUEST['sort']) && !IsNullOrEmpty($_REQUEST['sort']) ? $_REQUEST['sort'] : 'date';

require("../autoload.php");
use Vimeo\Vimeo;
$vimeo = new Vimeo($key, $secret, $token);



if($type == 'vimeo.channel'){

    //Get a list of videos in a Channel - https://developer.vimeo.com/api/playground/channels/{channel_id}/videos
    $result = $vimeo->request("/channels/$path/videos", array(
                                                    'page'=> $page,
                                                    'per_page' => $per_page,
                                                    'fields' => 'uri,name,description,duration,width,height,privacy,pictures.sizes',
                                                    'sort' => $sort,
                                                    'direction' => 'asc',                                   
                                                    'query' => $query));

}

echo json_encode($result);

【问题讨论】:

    标签: php joomla vimeo vimeo-api


    【解决方案1】:

    这是我的问题的解决方案。参数未正确加载。

    define( '_JEXEC', 1 );
    
    define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../..' ));
    require_once ( JPATH_BASE .'/includes/defines.php' );
    require_once ( JPATH_BASE .'/includes/framework.php' );
    
    $mainframe = JFactory::getApplication('site');
    $mainframe->initialise();
    
    $session = JFactory::getSession();
    
    jimport( 'joomla.application.module.helper' );
    
    $db = JFactory::getDBO();
    $db->setQuery("SELECT params FROM #__modules WHERE module = 'mod_module'");
    
    $module = $db->loadObject();
    $moduleParams = new JRegistry();
    $moduleParams->loadString($module->params);
    
        $key = $moduleParams->get('vimkey'); 
        $secret = $moduleParams->get('vimsecret'); 
        $token = $moduleParams->get('vimtoken'); 
    

    【讨论】:

      【解决方案2】:
      // What worked for me. Joomla 3.7
      
          // Init Joomla Framework      
      
          $joomlaBase = $_SERVER['DOCUMENT_ROOT'].'/mysitedirectory/'; // specific to my development environment        
          define( '_JEXEC', 1 );
          define('JPATH_BASE', $joomlaBase);
          define( 'DS', DIRECTORY_SEPARATOR );
          require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
          require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
          $mainframe = JFactory::getApplication('site');
          $mainframe->initialise();
      
          // Get params from Database
      
          $db = JFactory::getDBO();
          $db->setQuery("SELECT params FROM #__modules WHERE module = 'mod_my_module'");
          $module = $db->loadObject();
      
          $moduleParams = new JRegistry();
          $moduleParams->loadString($module->params);
          // This param_name value is set in the admin section of the module and defined in the xml manifest file as a field name.
          $key = $moduleParams->get('param_name', 'default value here not mandatory');
      
          // use $key as you like.
      

      这只是我的例子。谢谢@Frostbourn

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-21
        • 1970-01-01
        • 1970-01-01
        • 2013-07-28
        • 2022-10-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多