2013-04-30 60 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