简体   繁体   中英

How to get the latest release from Github API using JSON

Is is possible to get the latest release from github?

I have tried:

    var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    var JS = JSON.parse(this.responseText);     
  console.log(JS.tag_name)
  
  
  }
};
xmlhttp.open("GET", "https://api.github.com/repos/NAME/REPO/releases", true);
xmlhttp.send();

With the response from the console:

undefined

I think that there is an issue with getting the JSON file.

/repos/NAME/REPO/releases returns an array of releases, and you want to get the first one with JS[0].tag_name .

If you just need the latest release, use /repos/NAME/REPO/releases/latest and keep JS.tag_name .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM