2013-04-30 125 views
0

尝试向Salesforce.com发送经过验证的GET请求时,出现错误(INVALID_SESSION_ID)。无法验证Wordpress插件中的Salesforce

这里是它的全部,它基本上只是输出REST响应任何网页中有[MembershipTables]简码的身体插件:

if (!class_exists('WP_Http')) { 
     include_once(ABSPATH . WPINC . '/class-http.php'); 
    } 

    // This is obviously the real username 
    $username = '[email protected]'; 
    // And this is obviously the real password concatonated with the security token 
    $password = 'xxxxxxxxxxxxxx'; 

    function getMembershipTables() { 
    $api_url = 'https://na15.salesforce.com/services/apexrest/directory'; 
    $headers = array('Authorization' => 'Basic ' . base64_encode("$username:$password")); 
    $args = array('headers' => $headers); 
    $request = new WP_Http; 
    $result = $request->request($api_url, $args); 
    $body = $result['body']; 
    echo "$body"; 
    } 

    add_shortcode('MembershipTables', 'getMembershipTables'); 

我要指出,我能成功攻克这个尽管我使用的是使用旧SOAP API从Salesforce获得的会话令牌,以保持其等效(即没有客户端ID /密码)。

我做错了WP_Http?或者我不能使用基本身份验证来验证salesforce.com请求吗?

谢谢。

回答

0

salesforce API不支持基本身份验证,您需要使用sessionId调用它。您可以通过各种方法获取会话ID,包括交互式&程序OAuth2流程,以及通过Soap login调用。

0

Basis Interactive有一个类似的问题需要解决。当我在该项目上工作时,我选择通过预设表单插件和自定义JS Cookie PHP Wordpress插件来调用SalesForce CRM。我们通过在PHP中通过getRequest将销售数据传递给SalesForce CRM来开发对SalesForce CRM的自定义调用,可以轻松解决此问题。

试验场用途:

http://newtest.medullan.com/wp/?page_id=3089

这里是代码和循环逻辑查询

下载链接:

http://basisinteractive.net/webdesign.html#wordpress