javascript - Got error using curl with github api -
i using curl git repositories information. command used is:
curl https://api.github.com/search/repositories?page=2&q=language:javascript&sort=stars&order=desc
however, got is:
{ "message": "validation failed", "errors": [ { "resource": "search", "field": "q", "code": "missing" } ], "documentation_url": "https://developer.github.com/v3/search" }
if type directly url in browser obtain correct json output, when use curl fails. solution?
in curl's documentation show in 1 of examples:
main page ipv6 web server:
curl "http://[2001:1890:1112:1::20]/"
""
required surround url (due complexity). command should then:
curl "https://api.github.com/search/repositories?page=2&q=language:javascript&sort=stars&order=desc"
if want downloaded file, can use -o
option:
curl -o "https://api.github.com/search/repositories?page=2&q=language:javascript&sort=stars&order=desc"
if you're using windows command line can run winssl
's curl this zip (you need ssl version https
).
however, noticed javascript
tag in question, if you're planning use curl on client side, curl.js plugin may useful you.
on server side, if using php can use code:
<? $url="https://api.github.com/search/repositories?page=2&q=language:javascript&sort=stars&order=desc"; // initiate curl $ch = curl_init(); // disable ssl verification //curl_setopt($ch, curlopt_ssl_verifypeer, false); // return response, if false print response curl_setopt($ch, curlopt_returntransfer, true); // set url curl_setopt($ch, curlopt_url,$url); // execute $result=curl_exec($ch); // closing curl_close($ch); // dump beauty json :3 var_dump(json_decode($result, true)); ?>
this code placed "none" in here, in case, may need ssl verification enabled (so commented it).
curl_setopt allows set these required options (and url itself) when using curl getting json file.
Comments
Post a Comment