【问题标题】:PasteBin API bug? not allowing simple postPasteBin API 错误?不允许简单的帖子
【发布时间】:2011-08-25 15:34:56
【问题描述】:

我正在尝试发出一个 php api 请求,以简单地粘贴到 pastebin,我在 http://pastebin.com/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;


?>

【问题讨论】:

    标签: php string api post pastebin


    【解决方案1】:

    API 示例运行良好。我刚刚运行了你的代码(当然改变了 $api_dev_key,它第一次工作。输出:http://pastebin.com/eyn9tWNS

    尝试将其添加到脚本的顶部:

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

    它应该会给你一些关于正在发生的事情的更好的错误报告。

    【讨论】:

      猜你喜欢
      • 2016-11-07
      • 2018-02-23
      • 2016-03-29
      • 1970-01-01
      • 2018-10-30
      • 2016-12-15
      • 1970-01-01
      • 2014-10-24
      • 2013-01-15
      相关资源
      最近更新 更多