接入教程
1. 注册Pastebin账户并获取API密钥
2. 调用HTTP POST接口上传文本内容
3. 设置文本格式、过期时间等可选参数
4. API返回包含唯一URL的响应
5. 通过生成的链接分享或访问存储的文本
6. 可管理历史记录或删除已上传内容
创建新的粘贴
import requests
url = "https://pastebin.com/api/api_post.php"
api_key = "YOUR_API_KEY"
data = {
'api_dev_key': api_key,
'api_option': 'paste',
'api_paste_code': 'print(\"Hello, World!\")',
'api_paste_name': 'My First Paste',
'api_paste_format': 'python'
}
response = requests.post(url, data=data)
print(f"Paste URL: {response.text}")
获取用户粘贴列表
<?php
$api_key = 'YOUR_API_KEY';
$url = 'https://pastebin.com/api/api_post.php';
$data = array(
'api_dev_key' => $api_key,
'api_user_key' => '', // 留空或使用用户密钥
'api_option' => 'list',
'api_results_limit' => '10'
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo "Paste list: " . $response;
?>
删除一个粘贴
const axios = require('axios');
const apiKey = 'YOUR_API_KEY';
const url = 'https://pastebin.com/api/api_post.php';
const data = new URLSearchParams({
api_dev_key: apiKey,
api_user_key: '', // 留空或使用用户密钥
api_option: 'delete',
api_paste_key: 'paste_key_here'
});
axios.post(url, data)
.then(response => {
console.log(`Delete result: ${response.data}`);
})
.catch(error => {
console.error('Error:', error);
});
常见问题
如何获取Pastebin的API密钥?
访问Pastebin官网,注册并登录账户,然后在API页面生成您的API开发者密钥(api_dev_key)。
Pastebin API支持哪些数据格式?
Pastebin API主要支持纯文本格式,但可以通过api_paste_format参数指定语法高亮,如'python'、'php'、'javascript'等。
API调用有频率限制吗?
是的,Pastebin API对免费用户有请求频率限制,具体限制取决于您的账户类型,建议查阅官方文档了解最新限制。
Aitishiku.com