在过去的几天里,我一直在尝试通过 SalesForce 的 REST API 创建潜在客户,但我一生都无法让它发挥作用。我能够毫无问题地获得访问令牌,但从那时起,就创建潜在客户而言,我绝对没有运气。
我在所有文档中不断看到:
curl https://na1.salesforce.com/services/data/v20.0/sobjects/Account/ -H "Authorization: Bearer token -H "Content-Type: application/json" -d @newaccount.json"
我该如何在PHP的curl中做到这一点呢?我试了又试,但一点运气都没有。
这是我获取访问令牌的方式:
$ch = curl_init();
// set URL options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, "https://login.salesforce.com/services/oauth2/token?grant_type=password&client_id=".CONSUMER_KEY."&client_secret=".CONSUMER_SECRET."&username=".USERNAME."&password=".USERPASS.SECURITY_TOKEN);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab HTML
$data = curl_exec($ch);
$data = json_decode($data, true);
$code = $data['access_token'];
curl_close($ch);
我在这段代码之后尝试过做类似的事情,但是我没有运气。
$token_url = LOGIN_BASE_URL.'/services/oauth2/token';
$post_fields = array(
'code' => $code,
'grant_type' => 'authorization_code',
'client_id' => CONSUMER_KEY,
'client_secret' => CONSUMER_SECRET,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $token_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
$token_request_body = curl_exec($ch)
我只需要弄清楚如何在 SalesForce 中创建潜在客户,我不知道从这里该去哪里。任何帮助将不胜感激,因为我无法在任何地方找到对我有帮助的像样的文档。