vTiger REST登录错误:";无效的“授权令牌”;(php和/或python)
我正在尝试使用vTiger REST API,但我遇到了这个难题-我无法通过登录身份验证(!) 我已经按照指导方针和指示做了所有的事情,但是应该是一个相当简单的过程不起作用,总是给我提供相同的错误 我通过python和php以及在两个不同的服务器上使用过它,但结果是一样的 我做错了什么 PHP代码:vTiger REST登录错误:";无效的“授权令牌”;(php和/或python),php,rest,vtiger,vtigercrm,Php,Rest,Vtiger,Vtigercrm,我正在尝试使用vTiger REST API,但我遇到了这个难题-我无法通过登录身份验证(!) 我已经按照指导方针和指示做了所有的事情,但是应该是一个相当简单的过程不起作用,总是给我提供相同的错误 我通过python和php以及在两个不同的服务器上使用过它,但结果是一样的 我做错了什么 PHP代码: <?php $usercode = 'x5pox9oihbjp1pna'; $service_url = '<VTIGER ROOT>/webservice.php';
<?php
$usercode = 'x5pox9oihbjp1pna';
$service_url = '<VTIGER ROOT>/webservice.php';
$curl = curl_init($service_url);
$curl_post_data = array(
'operation'=> 'getchallenge',
'username' => 'admin',
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl ,CURLOPT_SSL_VERIFYPEER, false); //one server is ssl so i use this, the other isn't so i discard this when i try that one.
$curl_response = curl_exec($curl);
curl_close($curl);
echo "<p> First response: $curl_response<p>";
$x = json_decode($curl_response);
$token = var_export($x->result->token, true);
$token = substr($token, 1, -1); //getting rid of excess quote marks
echo "<p> token: $token </p>";
echo "<p> finished part 1 of php script</p>";
$combined = $token.$usercode;
echo "<p> token: $token </p>";
echo "<p> userAccessKey: $usercode </p>";
echo "<p> token + userAccessKey: $combined </p>";
$accessKeyHash= md5($combined);
echo "<p>Full Acces Key Hash: $accessKeyHash</p>";
$curl = curl_init($service_url);
$curl_post_data = array(
'operation'=> 'login',
'username' => 'admin',
'accessKey' => $accessKeyHash
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl ,CURLOPT_SSL_VERIFYPEER, false);
$curl_response = curl_exec($curl);
curl_close($curl);
echo "<p> Second response: $curl_response<p>";
echo "<p> finished part 2 of php script</p>";
尝试替换此:
$token = var_export($x->result->token, true);
$token = substr($token, 1, -1); //getting rid of excess quote marks
据此:
$token = $x->{'result'}->{'token'};
您正在对getchallenge操作执行POST请求。它应该是一个GET请求
更改您的第一个POST请求:
$curl = curl_init($service_url);
$curl_post_data = array(
'operation'=> 'getchallenge',
'username' => 'admin',
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl ,CURLOPT_SSL_VERIFYPEER, false);
$vtiger_user = 'admin';
$curl = curl_init($service_url . '?operation=getchallenge&username=' . $vtiger_user);
//$curl_post_data = array(
//'operation'=> 'getchallenge',
//'username' => 'admin',
//);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($curl, CURLOPT_POST, true);
//curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl ,CURLOPT_SSL_VERIFYPEER, false);
对于此GET请求:
$curl = curl_init($service_url);
$curl_post_data = array(
'operation'=> 'getchallenge',
'username' => 'admin',
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl ,CURLOPT_SSL_VERIFYPEER, false);
$vtiger_user = 'admin';
$curl = curl_init($service_url . '?operation=getchallenge&username=' . $vtiger_user);
//$curl_post_data = array(
//'operation'=> 'getchallenge',
//'username' => 'admin',
//);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($curl, CURLOPT_POST, true);
//curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl ,CURLOPT_SSL_VERIFYPEER, false);
您的第二个请求是确定的,它应该是一个POST请求。只要改变上面的部分,你就可以开始了
资料来源:我一直调试到它工作