-
-
Save MarketingPip/e748f657d6fdbe9731d278a1ca34f5ae to your computer and use it in GitHub Desktop.
Wikidata API: Get Label for Item ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"os" | |
) | |
func main() { | |
response, err := http.Get("https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q21&format=json&languages=en&props=labels") | |
if err != nil { | |
fmt.Printf("%s", err) | |
os.Exit(1) | |
} else { | |
defer response.Body.Close() | |
body, err := ioutil.ReadAll(response.Body) | |
if err != nil { | |
fmt.Printf("%s", err) | |
os.Exit(1) | |
} | |
value := make(map[string]interface{}) | |
err = json.Unmarshal(body, &value) | |
if err != nil { | |
fmt.Println(err) | |
} | |
fmt.Printf("%s\n", (((value["entities"]).(map[string]interface{})["Q21"]).(map[string]interface{})["labels"]).(map[string]interface{})["en"].(map[string]interface{})["value"].(string)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment