通过Rest api php从salesforce获取潜在客户的INVALID_SESSION_ID

时间:2017-07-06 04:30:35

标签: php rest session salesforce invalidation

嗨我需要通过rest api获得销售人员的线索,因为我已经通过rest api成功完成了oauth并得到了以下回复

stdClass Object
(
    [access_token] => 1111xxxxxxxx44444444444444
    [instance_url] => https://eu7.salesforce.com
    [id] => https://login.salesforce.com/id/000000000
    [token_type] => Bearer
    [issued_at] => xxxxxxxxxxxx
    [signature] => xxxxxxxxxxxx
)

之后获取联系线索我正在使用以下代码

$email = 'test_@gmail.com';
$query = 'SELECT Id, Email FROM Lead';
if($email != null){
$query .= sprintf("WHERE Email ='%s'", $email);
}
$url = $instance_url. '/services/data/v33.0/query?q=' . urlencode($query);
$paramsnew = "access_token=$access_token";
$urlcurl = curl_init($url);
curl_setopt($urlcurl, CURLOPT_HEADER, false);
curl_setopt($urlcurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($urlcurl, CURLOPT_POST, true);
curl_setopt($urlcurl, CURLOPT_POSTFIELDS, $paramsnew);
curl_setopt($urlcurl, CURLOPT_SSL_VERIFYPEER, false);
$urljson_response = curl_exec($urlcurl);
echo $urljson_response; 
curl_close($urlcurl);

但作为回应我正在低于

[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

请建议我如何解决这个问题。

2 个答案:

答案 0 :(得分:1)

最后我使用下面的代码修复了它。

$firstname = 'rohit';
$query = 'SELECT FirstName , LastName ,Id, Email FROM Lead ';
if($firstname != null){
$query .= sprintf("WHERE FirstName ='%s'", $firstname);
}
$url = $instance_url. '/services/data/v33.0/query?q=' . urlencode($query);
$paramsnew = "access_token=$access_token";
$urlcurl = curl_init($url);
curl_setopt($urlcurl, CURLOPT_HEADER, false);
curl_setopt($urlcurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($urlcurl, CURLOPT_HTTPGET, 1);
curl_setopt($urlcurl, CURLOPT_HTTPHEADER,
    array("Authorization: OAuth $access_token"));
curl_setopt($urlcurl, CURLOPT_SSL_VERIFYPEER, false);
$urljson_response = curl_exec($urlcurl);
print_r(json_decode($urljson_response)); 
curl_close($urlcurl);

我们需要传递像

这样的访问令牌
curl_setopt($urlcurl, CURLOPT_HTTPHEADER,
    array("Authorization: OAuth $access_token"));

我们需要使用curl的get方法。

curl_setopt($urlcurl, CURLOPT_HTTPGET, 1);

答案 1 :(得分:0)

新API版本的其他客户端响应的另外一个示例。

enter image description here