尝试在CodeIgniter中重用以下Dropbox API代码。问题是让它在类方法的约束下工作。 constuctors:
require_once('../dropbox-sdk-1.1.4/Dropbox/autoload.php');
use \Dropbox as dbx;
$accessToken = 'DROPBOX_ACCESSTOKEN';
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
需要类似以下内容,但不喜欢将\ Dropbox用作dbx'线,等等:
class Controller_name extends CI_Controller
{
public function __construct()
{
parent::__construct();
require_once('../dropbox-sdk-1.1.4/Dropbox/autoload.php');
use \Dropbox as dbx;
}
public function access_dropbox()
{
$accessToken = 'DROPBOX_ACCESSTOKEN';
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
$file = 'file.txt';
$f = fopen( $file, "rb" );
$result = $dbxClient->uploadFile( "/$file", dbx\WriteMode::add(), $f);
fclose($f);
}
}
使用下面的代码我收到以下错误消息:
遇到未捕获的异常
类型:Kunnu \ Dropbox \ Exceptions \ DropboxClientException
消息:调用API函数时出错" files / upload":HTTP标头 " Dropbox-API-Arg":路径:' db_backup'模式不匹配 (/(| [\ r \ n])的)|;&#39(NS:[0-9] +(/ )。?)|:&#39(ID *)。 ;
文件名: /opt/lampp/htdocs/codeig-smythes/vendor/kunalvarma05/dropbox-php-sdk/src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php
行号:59
$file_path = 'public/sql_backup/db_backup_' .date("Y-m-d"). '.sql';
require_once('../vendor/autoload.php');
$app = new Kunnu\Dropbox\DropboxApp(
'APP_KEY',
'APP_SECRET',
'ACCESS_TOKEN'
);
$dropbox = new Kunnu\Dropbox\Dropbox($app);
$dropboxFile = new Kunnu\Dropbox\DropboxFile(realpath($file_path));
$file = $dropbox->upload(
$dropboxFile, basename($file_path), array('autorename' => TRUE)
);