Github API的错误凭证 [英] Bad Credentials for Github API

查看:121
本文介绍了Github API的错误凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本,我正在尝试在bash中进行测试,使用curl进行一些操作,一个是创建一个新的仓库,第二个(尚未实现)是从git_url中获取.返回的json thats,我不确定我的 parse_json 函数是否允许我这样做,然后最终将示例提交消息推送到该存储库.

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.

脚本如下:

#!/usr/bin/env bash

set -eux

# Json Function: parse_json 'json string' key
function parse_json()
{
    echo $1 | sed -e 's/[{}]/''/g' | awk -F=':' -v RS=',' "\$1~/\"$2\"/ {print}" | sed -e "s/\"$2\"://" | 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"
}

我想知道是否是因为我用以下方式放入我的api密钥的原因: curl -i -H'Authorization:token $ apiKey ...'我尝试了"$ apiKey" ,但即使这样也不起作用.

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.

想法?

推荐答案

我以这种方式使用它:

curl -X 'POST' -u $MY_AUTH https://api.github.com/...

其中$ MY_AUTH是在github网站上生成的.看起来像:

where $MY_AUTH was generated in github website. It looks like:

export MY_AUTH="...hash...:x-oauth-basic"

这篇关于Github API的错误凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆