Salesforce-to-Wordpress:WP选项表没有填充SF中的json

时间:2015-03-05 20:53:43

标签: php wordpress curl salesforce integration

我正在尝试使用Salesforce中的数据填充WordPress网站。类似于this question的排序可能除了我正朝着相反的方向前进。我在this example上基于我的代码,当我尝试使用它时,这对我来说很好,但是一旦我用Wordpress尝试它就没那么多了。

从示例中,我只用下面的代码替换了demo_rest.php,在oauth_callback.php中更改了最后一行以返回到我在WordPress中的选项页面,正确地将其更改为config.php,并替换了index.html。当我这样做时,我在Salesforce中看到我确实从我的插件登录,但没有任何东西从那里回到WordPress。它没有显示在我想要的窗口中,或者使用应该生成的json更新mysql数据库。我做错了什么?

我的代码。

<?php

/*Assign global variables*/
$plugin_url = WP_PLUGIN_URL . '/my-plugin';
$options = array();


// adds plugin settings page in wordpress admin menu
function salesforce_menu(){

add_options_page( // wordpres helper function to add a settings page
    'Salesforce to WordPress Integrator',
    'Salesforce Integration',
    'manage_options',
    'salesforce-integrator',
    'salesforce_options_page'
    );
}

add_action('admin_menu','salesforce_menu');


function salesforce_options_page(){

    if ( !current_user_can('manage_options')){
        wp_die ('You do not have sifficient permissions to access this page.');

    }


global $plugin_url;
global $options;    


if( $access_token != '') { 


    $response = get_stories($instance_url, $access_token);//This is where I'm probably getting messed up. I'm trying to call the get_stories function (defined later)

    $options['response'] = $response;
    $options['last_updated'] =time();

    update_option ('storybank_approved', $options); //wp helper function to update the options table, hopefully with the results of my call to the API. 



}



$options = get_option('storybank_approved');

if ($options !=''){
    $response = $options['response'];
}

var_dump  ($response); //I want this to show me the json on my settings page just to ensure that I have a response, but it looks like I don't

    require('includes/options-page-wrapper.php');
}

//get salesforce records

function get_stories($instance_url, $access_token) {
    $query = "SELECT Id, Name from salesforce_Object__c LIMIT 100";
  $url = "$instance_url/services/data/v20.0/query?q=" . urlencode($query) ;

   $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER,
            array("Authorization: OAuth $access_token"));

    $json_response = curl_exec($curl);
    curl_close($curl); 

    $response =json_decode($json_response,true); 
    $total_size = $response['totalSize'];

    echo "$total_size record(s) returned<br/><br/>"; 

    foreach ((array) $response['records'] as $record) {                                   
        echo $record['Id'] . ", " . $record['Name']. "<br/>"; 

    }
    echo "<br/>";
    }
 ?>  

1 个答案:

答案 0 :(得分:0)

getStories函数未返回值。 $ response = get_stories($ instance_url,$ access_token); //必须返回一些东西。

//例如,为了简单起见,我删除了其余的代码。

function get_stories($instance_url, $access_token) {
       $response =json_decode($json_response,true); 
        return $response; 
}