SHARE
TWEET

create-gist-pastebin

selnomeria Feb 27th, 2020 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    
  2.    
  3.    
  4.     // send_data_to_pastebin ([ 'api_key'=>$GLOBALS['pastebin_api_key'], 'user_key'=>$GLOBALS['pastebin_user_key'], 'public'=>'1',  'expiration'=>'1M', 'content'=>$content,   'title'=>'untitled'  ])
  5.     public function create_pastebin( $content, $array= array())
  6.     {
  7.         // https://pastebin_com/api#1
  8.         $api_dev_key            = $array['api_key'];
  9.         $api_paste_code         = $content;
  10.         $api_paste_private      = $array['public'];
  11.         $api_paste_name         = $array['title'];
  12.         $api_paste_expire_date  = $array['expiration'];
  13.         $api_paste_format       = 'text';
  14.         $api_user_key           = $array['user_key']; // if an invalid or expired api_user_key is used, an error will spawn. If no api_user_key is used, a guest paste will be created
  15.         $url                    = str_replace('com','.com','https://pastebincom/api/api_post.php'); //funny, but pastebin links are detected as malware on hostings (they think fight malware by detecting "pastebing" phrase :)) (replacement url: https://goo.gl/bRV6dE )
  16.         $ch                     = curl_init($url);
  17.         curl_setopt($ch, CURLOPT_POST, true);
  18.         curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_option=paste&api_user_key='.$api_user_key.'&api_paste_private='.$api_paste_private.'&api_paste_name='.urlencode($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='.urlencode($api_paste_code).'');
  19.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  20.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
  21.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
  22.         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 9);
  23.         curl_setopt($ch, CURLOPT_REFERER, $url);    
  24.         curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  25.         curl_setopt($ch, CURLOPT_AUTOREFERER, true);  
  26.         curl_setopt($ch, CURLOPT_VERBOSE, 1);
  27.         curl_setopt($ch, CURLOPT_NOBODY, 0);
  28.         curl_setopt($ch, CURLOPT_VERBOSE, 1);
  29.         curl_setopt($ch, CURLOPT_NOBODY, 0);
  30.         $response           = curl_exec($ch);
  31.         return $response;
  32.     }
  33.  
  34.     // github api for GIST create
  35.     public function create_gist($content, $token=""){
  36.         $url = 'https://api.github.com/gists';
  37.         $ch = curl_init($url);
  38.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  39.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  40.         curl_setopt($ch, CURLOPT_POST, 1);
  41.         $header[]= "User-Agent: My App Name,Website or Email (for identification)";
  42.         $header[]= "Authorization: token $token"; //basic base64_encode("username:password");
  43.         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  44.         $data = array(
  45.         "description"=> "descr",
  46.         "public"=> true,
  47.         "files" => array(
  48.             "file1.txt"=> array(
  49.             "content" => $content
  50.             )
  51.         )
  52.         );
  53.         curl_setopt($ch, CURLOPT_POSTFIELDS,  json_encode($data) );
  54.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  55.         $response = curl_exec($ch);
  56.         curl_close($ch);
  57.         return $response;
  58.         // $response ['html_url'] -----> https://gist.github.com/0f62b7edeb2f03af1ec8d10558b7d67a
  59.         //           ['raw_url']  -----> https://gist.github usercontent.com/anonymous/0f62b7edebd1057d67a/raw/b004869d73c82d0d1/file1.txt
  60.         //           ['url']      -----> .... just contains some info about the api call
  61.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top