Opencart 2.2.0.0:您无权访问API

时间:2016-10-12 17:26:17

标签: php api permissions opencart

我正在使用Apache:2.4.7; PHP:5.4.24; Opencart:2.2.0.0; 我创建了名为=>的API REST并生成了一个API密钥。

IMAGE API page of admin opencart

我以这种方式登录此API:

$url = "http://localhost/upload/index.php?route=api/login";
$params = array('key=dpUFrufwZdbctqKaFckZz7WudebaAQO7orP6Y3QtpxTsbOyjNjpQZgIgAtp4SQVJWSfvpj2Acpis0E382EO3PhRcSMSJ6MpjV8EDXlWAtEC7aD3aGUou2yCL7ETpDARiIpzgy7auG2hhllIRjeUtXsiVUu6ENlJ7fBtIKvomjpTeaMXpIVklWx5CyxwIIGUA5CoYLGD4qPFvr6OAqDxJvhktMOjhj4DlKTvkTp0WzuoRBfRCDt8N4XIHMxbTIH1u'
    );

$parameters = implode('&', $params);

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $parameters);

//execute post
set_time_limit(120);
$result = curl_exec($ch);

//close connection
curl_close($ch);

print_r($result);

它让我变成了一个TOKEN,因此我可以使用此令牌访问此REST中的其他链接。但是,当我像这样使用TOKEN时:

$url = "http://localhost/upload/index.php?route=api/cart/products";
$params = array('token=bxXXgBX3NAue7dDnTC7pzQxf2qLZX8fB',
    );

$parameters = implode('&', $params);

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $parameters);

//execute post
set_time_limit(120);
$result = curl_exec($ch);

//close connection
curl_close($ch);

print_r($result);

它给我一个错误,如:

{"error": {"warning":"warning: you don't have permission to access API!"}}

有人能帮助我吗?

我已经尝试过:

- Permission for all user (user group)
- Pay atention to domain and sub domain
- Recreate the API and regenerate the API Key

1 个答案:

答案 0 :(得分:0)

您是否尝试将您的IP地址添加到Opencart Admin中允许的IP地址部分?