2010-12-13 3 views
1
<?php 

/* gets the data from a URL */ 
function get_data($url) 

{ 

    $ch = curl_init(); 

    $timeout = 5; 

    curl_setopt($ch,CURLOPT_URL,$url); 

    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 

    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); 

    $data = curl_exec($ch); 

    curl_close($ch); 
    return $data; 

} 
$paste_data=""; if(isset($_POST["paste_code"])) { $paste_data = $_POST["paste_code"]; } 
echo $paste_data; 
$returned_content = get_data('http://pastebin.com/api_public.php/paste_code(paste_data)'); 
echo $returned_content; 
?> 

이것은 내 PHP 코드입니다. 여기서 $ paste_data에는 새 페이지에 붙여 넣을 데이터가 들어 있습니다. paste_code (String) 함수를 사용하여 어떻게 붙여 넣을 수 있습니까?php에서 API를 사용하여 pastebin에 데이터를 붙여 넣는 방법은 무엇입니까?

+0

curl에 대해 너무 많이 모르고 있지만,'paste_code' 변수로'http : // pastebin.com/api_public.php'에'POST' 요청을해야한다는 것을 명심하십시오. 붙여 넣기 코드를 통과하지 못했고 올바른 매개 변수를 설정하지 않았습니다. – mpen

답변

2

documentation 유형 문자열이 당신이 만들고 싶어 붙여 넣기가의, paste_code 당신이

http://pastebin.com/api_public.php 

유일한 필수 매개 변수에 POST 요청을 제출할 필요가 있다고 말한다.

성공시 새 pastebin 개의 URL이 반환됩니다.

베어 뼈 예 :

$ch = curl_init("http://pastebin.com/api_public.php"); 
curl_setopt ($ch, CURLOPT_POST, true); 

// A new paste with the string "hello there SO" 
curl_setopt ($ch, CURLOPT_POSTFIELDS, "paste_code=hello there SO"); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_NOBODY, 0); 

$response = curl_exec($ch); 

echo $response; 

및 실행에 내가 얻을 :

> POST http://pastebin.com/api_public.php HTTP/1.1 
Host: pastebin.com 
Accept: */* 
Proxy-Connection: Keep-Alive 
Content-Length: 25 
Content-Type: application/x-www-form-urlencoded 

< HTTP/1.1 200 OK 
< Transfer-Encoding: chunked 
< Date: Mon, 13 Dec 2010 07:51:12 GMT 
< Content-Type: text/plain 
< Server: nginx/0.8.52 
< Vary: Accept-Encoding 
< X-Powered-By: PHP/5.3.4-dev 
< Via: 1.1 apac-nc06 (NetCache NetApp/6.0.6) 
< 
http://pastebin.com/Lc7kAw8Z* Closing connection #0 

은 분명히 응답이 URL이 http://pastebin.com/Lc7kAw8Z

를 방문하여 새 붙여 넣기가 포함 볼 수 있습니다 hello there SO

0

seach를 통해이 스레드에 따라 호 stumple가 여기에 2013 년에 작동 코드 :이 "포스트 2013 '에서 찾고 다른 사람에 대한 참고

<?php 
$data = 'Hello World!'; 

$apiKey = 'xxxxxxx'; // get it from pastebin.com 

$postData = array(
    'api_dev_key'   => $apiKey,    // your dev key 
    'api_option'   => 'paste',    // action to perform 
    'api_paste_code'  => utf8_decode($data), // the paste text 
    'api_paste_private'  => '1',     // 0=public 1=unlisted 2=private 
    'api_paste_expire_date' => '1D',    // paste expires in 1 day 
); 

$ch = curl_init('http://pastebin.com/api/api_post.php'); 
curl_setopt_array($ch, array(
    CURLOPT_POST => 1, 
    CURLOPT_POSTFIELDS => http_build_query($postData), 
    CURLOPT_RETURNTRANSFER => 1, 
)); 
$re = curl_exec($ch); 
curl_close($ch); 

$pasteId = end(explode('/', $re)); 
echo "Created new paste.\r\n Link:\t{$re}\r\n Raw:\t" . sprintf('http://pastebin.com/raw.php?i=%s', $pasteId) . "\r\n"; 
0

의 api_public.php의 POST가 중단되었습니다.

관련 문제