2013-09-06 5 views
3

GitHub Gist API를 살펴보면 API 키/인증없이 익명 사용자를 위해 Gist를 만들 수 있다는 것을 이해했습니다. 그렇지?API를 사용하여 GitHub Gist를 만드는 방법은 무엇입니까?

나는 다음과 같은 질문에 대한 답을 찾을 수 없습니다 :

  1. 는 어떤 제한 (기 스트의 수) 등을 생성 할 수 있습니까?
  2. 양식 텍스트 입력 필드에서 양식을 게시하여 요지를 작성할 수있는 예가 있습니까? 나는 아무것도 찾을 수 없었다.

감사합니다.

+1

나는 [인증되지 않은 속도 제한 요청] (http://developer.github.com/v3/#unauthenticated-rate-limited-requests) 카테고리에 속하는 인증되지 않은 요지를 생성하는 것이 확실합니다. –

답변

7

예. Github API V3 문서에서

: 기본 인증 또는 OAuth를를 사용하여 요청을

, 당신은 시간 당 5,000 요청을 만들 수 있습니다. 인증되지 않은 요청의 경우 속도 제한으로 시간당 최대 60 건의 요청을 처리 할 수 ​​있습니다. 내가 만든 예를 들어 여기에

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> 

자세한 내용은 documentation 참조를 다음과 같이

는 요점을 만들기 위해, 당신은 POST 요청을 보낼 수 있습니다.