Php Pastebin API粘贴数据

Php Pastebin API粘贴数据,php,pastebin,Php,Pastebin,我一直在尝试让PasteBinAPI运行,而不是告诉我pastebin链接,只是输出原始数据。PHP代码如下所示: <?php $api_dev_key = 'Stackoverflow(fake key)'; $api_paste_code = 'API.'; // your paste text $api_paste_private = '1'; // 0=public 1=unlisted 2=private $api_paste_e

我一直在尝试让PasteBinAPI运行,而不是告诉我pastebin链接,只是输出原始数据。PHP代码如下所示:

<?php

$api_dev_key        = 'Stackoverflow(fake key)';    
$api_paste_code         = 'API.'; // your paste text
$api_paste_private      = '1'; // 0=public 1=unlisted 2=private
$api_paste_expire_date  = 'N';
$api_paste_format       = 'php';
$api_paste_code     = urlencode($api_paste_code);

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

?>

通常情况下,这会将$api_paste_代码上传到pastebin中,显示为pastebin.com/St4ck0v3RFL0W,但我希望它生成原始数据

原始数据链接是,有人能帮忙吗


参考资料:

据我所知,响应包含创建内容时生成的Pastebin URL。像这样的Url:

http://pastebin.com/UIFdu235s
所以你只需要摆脱“http://pastebin.com/“这样做:

然后,将其附加到您提供的原始url:

$url_raw = "http://pastebin.com/raw.php?i=".$id;

您将获得原始数据。

据我所知,响应包含创建内容时生成的Pastebin URL。像这样的Url:

http://pastebin.com/UIFdu235s
所以你只需要摆脱“http://pastebin.com/“这样做:

然后,将其附加到您提供的原始url:

$url_raw = "http://pastebin.com/raw.php?i=".$id;

您将获得原始数据。

首先,请注意,您必须向pastebin.com API发送
POST
请求,而不是
get
。所以不要在输入数据上使用
urlencode()

要从页面url获取原始粘贴url,您有几个选项。但最简单的可能是:

$apiResonse = 'http://pastebin.com/ABC123';
$raw        = str_replace('m/', 'm/raw.php?i=', $apiResponse);
最后,这里是一个完整的示例:

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

$apiKey  = 'xxxxxxx';                         // get it from pastebin.com
$apiHost = 'http://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
);

$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL             => "{$apiHost}api/api_post.php",
    CURLOPT_RETURNTRANSFER  => 1,
    CURLOPT_POST            => 1,
    CURLOPT_POSTFIELDS      => http_build_query($postData),
));

$result = curl_exec($ch); // on success, some string like 'http://pastebin.com/ABC123'
curl_close($ch);

if ($result) {
    $pasteId = str_replace($apiHost, '', $result);
    $rawLink = "{$apiHost}raw.php?i={$pasteId}";

    echo "Created new paste.\r\n Paste ID:\t{$pasteId}\r\n Page Link:\t{$result}\r\n Raw Link:\t{$rawLink}\r\n";
}

首先,请注意,您必须向pastebin.com API发送
POST
请求,而不是
GET
。所以不要在输入数据上使用
urlencode()

要从页面url获取原始粘贴url,您有几个选项。但最简单的可能是:

$apiResonse = 'http://pastebin.com/ABC123';
$raw        = str_replace('m/', 'm/raw.php?i=', $apiResponse);
最后,这里是一个完整的示例:

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

$apiKey  = 'xxxxxxx';                         // get it from pastebin.com
$apiHost = 'http://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
);

$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL             => "{$apiHost}api/api_post.php",
    CURLOPT_RETURNTRANSFER  => 1,
    CURLOPT_POST            => 1,
    CURLOPT_POSTFIELDS      => http_build_query($postData),
));

$result = curl_exec($ch); // on success, some string like 'http://pastebin.com/ABC123'
curl_close($ch);

if ($result) {
    $pasteId = str_replace($apiHost, '', $result);
    $rawLink = "{$apiHost}raw.php?i={$pasteId}";

    echo "Created new paste.\r\n Paste ID:\t{$pasteId}\r\n Page Link:\t{$result}\r\n Raw Link:\t{$rawLink}\r\n";
}

但是你从哪里得到上一步收到的
$url
?我无法从您的代码(从提供的图像)上看到您实际获取了接收到的url。但是您在上一步从何处获取了
$url\u received\u
?我在你的代码(从提供的图片)上看不到你实际获取了收到的url。