如何使用curl访问github graphql API

问题描述:

在引用此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个小时试图找出它,并尝试了不同的例子,但没有一个能够工作。能否请你还跟帮我解决这个

你只需要转义双引号是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

编辑,谢谢。 –