bash Github API 的错误凭证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27669504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bad Credentials for Github API
提问by TheWebs
I have the following script, which I am trying to test out in bash, using curl to do a couple things, one is to create a new repo, the second - which is not implemented yet - is to get the git_url from the json thats returned, which I'm not sure if my parse_json
function will let me do that and then finally to push a sample commit message to that repo.
我有以下脚本,我试图在 bash 中测试它,使用 curl 做几件事,一个是创建一个新的 repo,第二个 - 尚未实现 - 是从 json 中获取 git_url返回,我不确定我的parse_json
函数是否会让我这样做,然后最后将示例提交消息推送到该存储库。
the script is as follows:
脚本如下:
#!/usr/bin/env bash
set -eux
# Json Function: parse_json 'json string' key
function parse_json()
{
echo | sed -e 's/[{}]/''/g' | awk -F=':' -v RS=',' "$1~/\"\"/ {print}" | sed -e "s/\"\"://" | tr -d "\n\t" | sed -e 's/\"/"/g' | sed -e 's/\\/\/g' | sed -e 's/^[ \t]*//g' | sed -e 's/^"//' -e 's/"$//'
}
git_create_repo() {
read -e -p "Please enter your API Key: " apiKey
read -e -p "Repo Name: " repoName
read -e -p "Repo Description: " repoDescription
# Use the API to create a a repository
response=$(curl -i -H 'Authorization: token $apiKey' \
-d '{ \
"name": "$repoName", \
"description": "$repoDescription", \
"private": false, \
"license_template": "mit" \
}' \
https://api.github.com/AdamKyle/repos)
echo $response
}
git_create_repo
When I go through all the steps I get:
当我完成所有步骤时,我得到:
{
"message": "Bad credentials",
"documentation_url": "https://developer.github.com/v3"
}
I am wondering if its because of the way I am putting in my api key with: curl -i -H 'Authorization: token $apiKey ...'
I have tried "$apiKey"
but even that doesn't work.
我想知道是不是因为我输入 api 密钥的方式:curl -i -H 'Authorization: token $apiKey ...'
我已经尝试过,"$apiKey"
但即使这样也行不通。
Ideas?
想法?
回答by Lajos Veres
I use it this way:
我这样使用它:
curl -X 'POST' -u $MY_AUTH https://api.github.com/...
where $MY_AUTH was generated in github website. It looks like:
$MY_AUTH 是在 github 网站中生成的。看起来像:
export MY_AUTH="...hash...:x-oauth-basic"