如何创建一个GitHub的要点与API? [英] How to create a GitHub Gist with API?

查看:248
本文介绍了如何创建一个GitHub的要点与API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过查看GitHub上吉斯特API,我明白,这是可能创造主旨没有任何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:


    要创建
  1. 是否有任何限制(学家数)等?

  2. 有没有办法,我可以张贴从表单文本输入字段code创建一个要点的​​例子吗?我找不到任何。

感谢有关此的任何信息。

Thanks for any information about this.

推荐答案

是的。

Github的API V3 文档:

有关使用基本身份验证或OAuth的请求,你可以高达每小时5000的要求。对于未经授权的请求,速率限制使您可以高达每小时60个请求。

For requests using Basic Authentication or OAuth, you can make up to 5,000 requests per hour. For unauthenticated requests, the rate limit allows you to make up to 60 requests per hour.

有关创建一个要点,可以按如下方式发送 POST 要求:

For creating a gist, you can send a POST request as follows:

POST /gists

下面是我做了一个例子:

Here's an example I made:

<?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>

参阅文档以获取更多信息。

这篇关于如何创建一个GitHub的要点与API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆