[英]PHP Use oAuth to consume SalesForce SOAP API
I'm trying to use oAuth to consume the SOAP API via PHP. 我正在尝试使用oAuth通过PHP使用SOAP API。
I have successfully obtained both my instance URL & my access token. 我已经成功获取了实例URL和访问令牌。 However, it would appear I cannot use the login() method with oAuth.
但是,似乎我无法在oAuth中使用login()方法。 I've tried setting the session headers manually, but I get an error:
我尝试手动设置会话标头,但出现错误:
UNKNOWN_EXCEPTION: Destination URL not reset.
UNKNOWN_EXCEPTION:未重置目标URL。 The URL returned from login must be set in the SforceService
从登录返回的URL必须在SforceService中设置
Could someone please show me how I could set the API sessionId header to use the access_token I got from my oAuth flow instead? 有人可以告诉我如何设置API sessionId标头以使用从oAuth流中获取的access_token吗? I saw a couple links from long ago but they're all broken/outdated.
我看到很久以前的几个链接,但它们都已损坏/过时。
Here's my existing code: 这是我现有的代码:
$access_token = isset($_GET['access_token']);
$instance_url = isset($_GET['instance_url']);
If(!$access_token) {
header('Location: ********************');
}
try {
define("SOAP_CLIENT_BASEDIR", "../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
require_once (SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php');
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
$mySforceConnection->setSessionHeader('sessionId',$access_token);
$mySforceConnection->setSessionHeader('serverUrl','https://<<instance>>/services/Soap/u/27.0/<<orgID>>');
$query = "select id from user where name='chris miller'";
$response = $mySforceConnection->query($query);
} catch (Exception $e) {
print_r($mySforceConnection->getLastRequest());
echo '<p style="margin-left:50px;color:red;font-weight:bold;">' . $e->faultstring . '</p>';
}
The only example I could find used a deprecated method attach() that would essentially append the sessionId & server URL to your session header. 我可以找到的唯一示例使用了不推荐使用的方法attach(),该方法实际上会将sessionId和服务器URL附加到会话标头中。 But I couldn't find that method anywhere
但是我在任何地方都找不到这种方法
将setEndpoint与实例URL一起使用,以便SOAP客户端知道将请求发送到哪里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.