![](/img/trans.png)
[英]How to set username and password in PHP script for Salesforce login using Rest API
[英]Salesforce php REST API with automatic login
我现在正把这头发拖过来。 我遵循了以下示例:
http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php
但是这里用户被发送到登录表单并需要登录。 相反,我想在我的代码中发布该数据,而不是让用户登录,但我的应用程序会自动执行此操作。
如果有人可以发布一个关于如何使用oAuth进行操作的示例,我会非常感激,因为我并不急于使用那个膨胀的SOAP实现。
干杯啦!
似乎经过一些修补我的尝试取得了成功::
$loginurl = "https://login.salesforce.com/services/oauth2/token";
$params = "grant_type=password"
. "&client_id=" . CLIENT_ID
. "&client_secret=" . CLIENT_SECRET
. "&username=" . USER_NAME
. "&password=" . PASSWORD;
$curl = curl_init($loginurl);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
die("Error: call to URL failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
echo $json_response;
现在剩下要做的就是将该响应中的access_token&instance_url存储到会话变量中,并解决我们的对象问题。
我希望以上帮助其他有类似问题的人。
2018答案:
发出POST请求:
grant_type
:必须是此身份验证流的password
。 client_id
:来自连接的应用程序定义的使用者密钥。 client_secret
:来自连接的应用程序定义的Consumer Secret。 除非在连接的应用程序定义中未启用“Web服务器流的要求密钥”设置,否则必需。 username
:最终用户的用户名。 password
:最终用户的密码。 例:
grant_type=password&client_id=3MVG9lKcPoNINVBIPJjdw1J9LLM82Hn FVVX19KY1uA5mu0QqEWhqKpoW3svG3XHrXDiCQjK1mdgAvhCscA9GE&client_secret= 1955279925675241571&username=testuser%40salesforce.com&password=mypassword123456
有关详细信息,请参见上面的链
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.