api - How to create or update file using Github content api
问题描述
I wanna update or create file (such as ~~.yml, ~~.json) with Github content API.
So I followed directions written in the github docs, it says to request PUT
method for update or create. I wrote code like below, but I got 404 error,,
axios({
method: 'put',
url:
'https://api.github.com/repos/{owner}/{repo}/contents/package.json',
data: {
message: 'put method test',
content: { newData },
sha: { sha },
},
}).then((res) => console.log(res));
There is encoded code in the {content} btoa(content)
解决方案
404 probably means an access right issue: a PUT method needs for you to be properly authenticated in order for GitHub to determine if you have the right to put anything in that repository.
See "Other authentication methods", using a PAT (Personal access token) and a dedicated "Authorization: token TOKEN
" header
And you need to replace {owner}/{repo}
by the actual owner GitHub account name, and GitHub repository name: those are placeholders.
推荐阅读
- node.js - 如何在 NodeJS Express 服务器中正确设置 Angular 以进行生产?
- php - 从 symfony 4 中彻底删除实体
- python - 在没有高级 API 的情况下重新训练 CNN
- javascript - Javascript计数器,点击特定数字后弹出模式
- javascript - Websocket 处理不同的数据 - 不同的端点?
- c++ - C/C++ UPNP NAT 遍历 Winsock 实现
- python - 意外的关键字参数“详细”:scipy curve_fit
- php - mysql所有查询都不能在php同一个文件中工作
- python - 如何在 Python(网络爬虫)中调用 Javascript 函数?
- azure - 尝试从 Azure 容器实例打开 FQDN 时如何解决“无法连接到服务器”错误?