![](/img/trans.png)
[英]How to create and update a file in a Github repository with PHP and Github API?
[英]How to create a GitHub Gist with API?
通過查看GitHub Gist API,我了解到可以為匿名用戶創建Gist創建而無需任何API密鑰/身份驗證。 是這樣嗎?
我找不到以下問題的答案:
感謝您提供相關信息。
是。
來自Github API V3文檔:
對於使用基本身份驗證或OAuth的請求,您每小時最多可以請求5,000個請求。 對於未經身份驗證的請求,速率限制允許您每小時最多發出60個請求。
要創建一個要點,您可以發送POST
請求,如下所示:
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>
有關更多信息,請參閱文檔 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.