使用R使用API​​在Github存储库中创建文件

时间:2015-05-12 20:50:58

标签: r github github-api

我想使用对Github API的PUT请求在Github存储库中创建一个文件,更多信息请参见:https://developer.github.com/v3/repos/contents/#create-a-file

这是我用来验证的代码(您需要更改您的应用和密码):

library(httr)
library(RCurl)

# 1. Find OAuth settings for github:
#    http://developer.github.com/v3/oauth/
oauth_endpoints("github")

# 2. Register an application at https://github.com/settings/applications
#    Insert your values below - if secret is omitted, it will look it up in
#    the GITHUB_CONSUMER_SECRET environmental variable.
#
#    Use http://localhost:1410 as the callback url
myapp <- oauth_app("TestApp", "app-number","secret-number")
scope <- 'public_repo'
# 3. Get OAuth credentials
github_token <- oauth2.0_token(oauth_endpoints("github"),scope=scope, myapp)

我的Github用户名是aruizga7,存储库名称是-repoName-。我用来对Github API执行PUT请求的代码是:

url = "https://api.github.com/repos/aruizga7/-repoName-/contents/path"
data = list("message"=("my commit message"),
            "content"=  upload_file(("C:/example.txt")))
r<-PUT(url,body = data,config(token = github_token),encode = "json")
content(r)

此请求的结果如下:

$message
[1] "Invalid request.\n\n[\"my commit message\"] is not a string.\n\"content\" wasn't supplied."

$documentation_url
[1] "https://developer.github.com/v3/repos/contents/"

任何人都可以提供帮助吗?

谢谢!

0 个答案:

没有答案