【问题标题】:create pastes inside folder with pastebin.com api?使用 pastebin.com api 在文件夹内创建粘贴?
【发布时间】:2019-08-25 18:20:54
【问题描述】:

在 pastebin.com 上创建文件夹后,如何使用 api 将粘贴上传到该文件夹​​?我在https://pastebin.com/api 的 API 文档中真的找不到任何提及文件夹的内容(事实上,folder 这个词根本没有出现在文档中,运行curl 'https://pastebin.com/api' -s | grep -i folder | wc -l 返回 0),我想这样做使用 php + curl_ api 如果这很重要(但我怀疑它是)

【问题讨论】:

    标签: php php-curl pastebin


    【解决方案1】:

    这显然不是一个好的解决方案,但它是我迄今为止发现的唯一一个(我也询问了 pastebin.com 管理员电子邮件,但尚未得到回复):只是伪装成浏览器,完全绕过api,因为浏览器可以上传到文件夹。此实现使用hhb_curl,但它应该很容易移植到任何其他类似 curl 的 api。

    class Pastebin_to_folder_argument{
        public $username;
        public $password;
        public $folder_id;
        public $text;
        public $title="untitled";
        public $syntax_highlight_language=1;
        public $paste_expire="N";
        public $paste_exposure=1;
        public $paste_private=true;
    }
    $arg=new Pastebin_to_folder_argument();
    $arg->username=USERNAME;
    $arg->password=PASSWORD;
    $arg->folder_id="rtUNY7pF"; 
    $arg->text="test paste from PHP!";
    var_dump(pastebin_to_folder($arg));
    function pastebin_to_folder(Pastebin_to_folder_argument $arg):string
    {
        $hc = new hhb_curl('', true);
        $html = $hc->setopt_array(array(
            CURLOPT_URL => 'https://pastebin.com/login',
            CURLOPT_POST => 1,
            CURLOPT_POSTFIELDS => http_build_query(array(
                'submit_hidden' => 'submit_hidden',
                'user_name' => $arg->username,
                'user_password' => $arg->password,
                'submit' => 'Login'
            ))
        ))->exec()->getStdOut();
        if (false === strpos($html, 'onclick="location.href=\'/logout\'"')) {
            ob_start();
            var_dump($html);
            $str = ob_get_clean();
            fwrite(STDERR, $str);
            throw new \RuntimeException("failed to login! (could not find the logout button - html printed to stderr for debugging.)");
        }
        $html=$hc->setopt(CURLOPT_HTTPGET,1)->exec('https://pastebin.com')->getStdOut();
        //hhb_var_dump($html) & die();
        //<input type="hidden" name="csrf_token_post" value="MTU2NjkxOTQ4MjJnRGxJMUowSjVMV1pYdU8yWUV3VVBNbVg2NXFlZmZs">
        $domd=@DOMDocument::loadHTML($html);
        $xp=new DOMXPath($domd);
        $csrf_token=$xp->query("//input[@name='csrf_token_post']")->item(0)->getAttribute("value");
        $max_file_size=$xp->query("//input[@name='MAX_FILE_SIZE']")->item(0)->getAttribute("value");
        $shitty_workaround_tmpfile=tmpfile();
        $shitty_workaround=new CURLFile(stream_get_meta_data($shitty_workaround_tmpfile)['uri'],"application/octet-stream","");
    
        $html=$hc->setopt_array(array(
            CURLOPT_URL=>'https://pastebin.com/post.php',
            CURLOPT_POST=>1,
            CURLOPT_POSTFIELDS=>array(
                'csrf_token_post'=>$csrf_token,
                'submit_hidden'=>'submit_hidden',
                'item_upload'=>$shitty_workaround, 
                'file_post'=>'',
                'MAX_FILE_SIZE'=>$max_file_size,
                'paste_code'=>$arg->text,
                'paste_format'=>$arg->syntax_highlight_language,
                'paste_expire_date'=>$arg->paste_expire,
                'paste_private'=>$arg->paste_private,
                'paste_folder'=>$arg->folder_id,
                'new_folder_name'=>null,
                'paste_name'=>$arg->title,
            )
        ))->exec()->getStdOut();
        unset($shitty_workaround);
        fclose($shitty_workaround_tmpfile);
        //hhb_var_dump($html);
        // TODO: verify that upload was actually successfull?
        return $hc->getinfo(CURLINFO_EFFECTIVE_URL); // the paste url.
    }
    

    【讨论】:

      猜你喜欢
      • 2018-10-22
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多