我正在尝试使用EasyPost与Codeigniter建立一个电子商务商店,让客户选择他们想要的运费。
我已将CURL库和REST库加载到我的项目中,然后输入以下代码:
class Shipping extends CI_Controller {
function __construct() {
parent::__construct();
error_reporting(E_ALL);
$this->rest->initialize(array(
'server' => 'https://api.easypost.com/v2'
));
$this->rest->api_key('replaced-hidden-api_key');
}
function index() {
$result = $this->rest->get('/shipments');
var_dump($result);
}
}
当我加载www.myurl.com/shipping时,我会收到EasyPost的登录页面但是在我的网址下?世界上我做错了什么?我不明白每个人怎么说api很容易。
否则
如何在不为文件创建类的情况下将EasyPost库包含到codeigniter中。 These are the files I'm talking about
答案 0 :(得分:0)
您是否包含所有必填字段?我只看到你包含了api_key。
以下是发货的其他必填字段:
to_address Address required
from_address Address required
parcel Parcel required
PHP中的示例:
$to_address = \EasyPost\Address::create(...);
$from_address = \EasyPost\Address::create(...);
$parcel = \EasyPost\Parcel::create(...);
$customs_info = \EasyPost\CustomsInfo::create(...);
\EasyPost\Shipment::create(array(
"to_address" => $to_address,
"from_address" => $from_address,
"parcel" => $parcel,
"customs_info" => $customs_info
));
来源: