2011-05-14 36 views
2

我試圖讓一個php api請求簡單地粘貼到pastebin,我在http://pastebin.com/api找到一個例子,它是相當海峽,所以我不認爲會有任何麻煩。但這個例子似乎並沒有奏效。我不斷收到響應PasteBin API錯誤?不允許簡單的發佈

Bad API request, invalid api_option 

但是你可以清楚地看到它設置它創建的字符串中api_option=paste ...

,並在文件中,它說

Creating A New Paste, [Required Parameters] 
Include all the following POST parameters when you request the URL: 

1. api_dev_key - which is your unique API Developers Key. 
2. api_option - set as 'paste', this will indicate you want to create a new paste. 
3. api_paste_code - this is the text that will be written inside your paste. 

Leaving any of these parameters out will result in an error. 

所以... 。我認爲它看起來不錯,除了它提供的例子。

任何人有任何想法這裏發生了什麼?

<?php 


$api_dev_key   = '1234'; // your api_developer_key 
$api_paste_code   = 'some random text to test'; // your paste text 
$api_paste_private  = '0'; // 0=public 1=private 
$api_paste_name   = 'savelogtest'; // name or title of your paste 
$api_paste_expire_date = '10M'; 
$api_paste_format  = 'php'; 
$api_user_key   = ''; // if invalid key or no key is used, the paste will be create as a guest 
$api_paste_name   = urlencode($api_paste_name); 
$api_paste_code   = urlencode($api_paste_code); 


$url    = 'http://pastebin.com/api/api_post.php'; 
$ch     = curl_init($url); 

curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_option=paste&api_user_key='.$api_user_key.'&api_paste_private='.$api_paste_private.'&api_paste_name='.$api_paste_name.'&api_paste_expire_date='.$api_paste_expire_date.'&api_paste_format='.$api_paste_format.'&api_dev_key='.$api_dev_key.'&api_paste_code='.$api_paste_code.''); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_NOBODY, 0); 

$response   = curl_exec($ch); 
echo $response; 


?> 

回答

1

API示例正常工作。我只是跑你的密碼(當然改變了$ api_dev_key,和它的工作第一次輸出:http://pastebin.com/eyn9tWNS

嘗試,並在你的腳本的頂部添加此:

error_reporting(E_ALL); 
    ini_set("display_errors", "on"); 

它應該給你一些更好錯誤報告。

相關問題