本文介绍了如何使用 API 创建 GitHub Gist?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过查看 GitHub Gist API,我了解到可以为匿名用户创建 Gist create,而无需任何 API 密钥/身份验证.是这样吗?
By looking at GitHub Gist API, I understood that it is possible to create the Gist create for anonymous users without any API keys/authentication. Is it so?
我找不到以下问题的答案:
I could not find answers to following questions:
- 是否有要创建的任何限制(要点数量)等?
- 是否有任何示例可以让我发布表单文本输入字段中的代码以创建要点?我找不到.
感谢您提供有关此的任何信息.
Thanks for any information about this.
推荐答案
是的.
来自 Github API V3 文档:
对于使用基本身份验证或 OAuth 的请求,您每小时最多可以发出 5,000 个请求.对于未经身份验证的请求,速率限制允许您每小时最多发出 60 个请求.
要创建一个要点,您可以发送一个 POST
请求,如下所示:
For creating a gist, you can send a POST
request as follows:
POST /gists
这是我做的一个例子:
<?php
if (isset($_POST['button']))
{
$code = $_POST['code'];
# Creating the array
$data = array(
'description' => 'description for your gist',
'public' => 1,
'files' => array(
'foo.php' => array('content' => 'sdsd'),
),
);
$data_string = json_encode($data);
# Sending the data using cURL
$url = 'https://api.github.com/gists';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
# Parsing the response
$decoded = json_decode($response, TRUE);
$gistlink = $decoded['html_url'];
echo $gistlink;
}
?>
<form action="" method="post">
Code:
<textarea name="code" cols="25" rows="10"/> </textarea>
<input type="submit" name="button"/>
</form>
有关详细信息,请参阅文档.
Refer to the documentation for more information.
这篇关于如何使用 API 创建 GitHub Gist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!