2011-05-14 3 views
2

나는 PHP 붙여 넣기를 간단하게 붙여 넣으려고 요청하고있어. 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. 

이렇게 말한다 ... .i 그들이 제공 한 예 외에도 그것이 옳았다 고 생각했습니다.

누구나 여기에 무슨 일이 일어나고 있는지 아이디어가 있습니까?

<?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"); 

그것은 당신에게 제공해야 더 좋은 무슨 일이 일어나고 있는지에 대한 오류보고

관련 문제