2014-04-28 63 views
0

這是API的GetResponse的爲https://github.com/robertstaddon/GetResponse-PHP-Wrapper/blob/master/PHPwrapper/GetResponseAPI.class.php GETRESPONSE使用API​​來獲取競選

if(isset($_POST['Generate'])) 
{ 
    require_once dirname(__FILE__) . '/GetResponseAPI.class.php'; 
    $api = new GetResponse('APIKEY HERE'); 
    $campaigns = (array)$api->getCampaigns(); 
    $campaignIDs = array_keys($campaigns); 
    $campaign = $api->getCampaignByID($campaignIDs[0]); 
    var_dump($campaigns, $campaign); 
} 

這是HTML代碼是用PHP在同一頁上的主要環節。

<form method="post" action=""> 
<select name="Campaign" id="Campaign"> 
<?php foreach ($campaign as $campaignID => $value) { ?> 
<option value="<?php echo $campaignID;?>"><?php echo $value;?></option>  
<?php } ?> 
</select> 
<input type="submit" value="Generate" name="Generate" id="Generate"/> 
</form> 

我在同一頁的頂部得到林的錯誤是以下內容: 陣列(0){} NULL

回答

1

嘗試這個代碼:

# DOWNLOAD FILE FROM - http://jsonrpcphp.org/?page=download&lang=en 
require_once 'jsonRPCClient.php'; 

# your API key is available at 
# https://app.getresponse.com/my_api_key.html 
$api_key = 'YOUR_API_KEY_HERE'; 

# API 2.x URL 
$api_url = 'http://api2.getresponse.com'; 

# initialize JSON-RPC client 
$client = new jsonRPCClient($api_url); 

# get campaigns list 
$campaigns = $client->get_campaigns(
    $api_key 
); 

# All Your Campaigns List 
print_r($campaigns);