1

I have saw professional answer about "Get github repos list via jquery",now I want to use jquery to get this repo's latest release tag_name, the link is https://api.github.com/repos/carry0987/Messageboard/releases/latest

How can I get tag_name via jquery like this answer?Link:Github API List all repositories and repo's content

carry0987
  • 117
  • 1
  • 2
  • 14

2 Answers2

2

Request format fort lastesst release is:

GET /repos/:owner/:repo/releases/latest

you can do something like this. I simply show it in console log

$.ajax({
    type: "GET",
    url: "https://api.github.com/repos/carry0987/Messageboard/releases/latest",
    dataType: "json",
    success: function(result) {
    
        console.log( "tag name: "+ result.tag_name );
        console.log( "tag created at: "+ result.created_at );
        console.log( "tag published at: "+ result.published_at  );

    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Novy
  • 1,436
  • 1
  • 14
  • 26
  • Why can it work ?! I use php via $json = file_get_contents('url_here'); $obj = json_decode($json); echo $obj->tag_name; but it give me HTTP 403 Error... – carry0987 Mar 15 '18 at 10:07
  • @carry0987 I add an example for you to avoid the 403 – Novy Mar 15 '18 at 10:33
0

I am not sure if we can add another topic here. May be you would have to rephrase a little bit your first request for integrate php part.

In php it is a matter of security in github web service if you have a 403 forbidden.

try this:

<?php 
ini_set('user_agent', 'Mozilla/4.0 (compatible; MSIE 6.0)');
ini_set('max_execution_time', 300);
 $json =file_get_contents("https://api.github.com/repos/carry0987/Messageboard/releases/latest") ;
 //get a json not an array
 $myArray = json_decode($json,true);
 foreach( $myArray as $key => $value ){
     echo $key."\t=>\t".$value."\n";
 }
?>

Now you can do your thing i hope

Novy
  • 1,436
  • 1
  • 14
  • 26
  • I will add another topic about php error,thanks for your recommendation! (My php give me 504 Timeout,I will describe it in new topic~ – carry0987 Mar 15 '18 at 11:10