2017-02-03 85 views
4

在引用此guide之後,我需要通過使用curl來訪問github graphql以進行測試。我想這個簡單的命令如何使用curl訪問github graphql API

curl -i -H "Authorization: bearer myGithubAccessToken" -X POST -d '{"query": "query {repository(owner: "wso2", name: "product-is") {description}}"}' https://api.github.com/graphql 

,但它給了我

問題解析JSON

什麼,我做錯了。我花了近2個小時試圖找出它,並嘗試了不同的例子,但沒有一個能夠工作。能否請你還跟幫我解決這個

回答

6

你只需要轉義雙引號是JSON的內側,

$ curl -i -H 'Content-Type: application/json' -H "Authorization: bearer myGithubAccessToken" -X POST -d '{"query": "query {repository(owner: \"wso2\", name: \"product-is\") {description}}"}' https://api.github.com/graphql 
+2

我來到這個答案試圖訪問我自己的Django /基於石墨烯的查詢API;爲此,我需要一個額外的'-H'Content-Type:application/json'' –

+0

編輯,謝謝。 –