我正在 Adobe Air 中制作一个小应用程序,我需要与 Github Gist API 进行交互。但是我有点卡住了。
如果您不熟悉 Adobe Air,您仍然可以提供帮助,XMLHttpRequest
javascript 对象可以执行跨域请求,因为没有这样的域。所以这里没有任何特定于 Adobe Air 的内容。
我被卡住的地方是我认为我需要验证自己然后进行 POST。就是没看懂
最佳答案
您的脚本的问题在于,尽管您发送的是 POST 方法,但您将数据添加到 URL 中,就好像它是 GET 一样。您只需要将 xmlhttp.send(NULL)
更改为 xmlhttp.send(data)
,其中 data
是您要附加到的查询数据gists
之前的 URL(包括文件和身份验证信息)。
作为一个简单的例子,这里是 a bash script 的摘录创建一个新的要点:
#!/usr/bin/env bash
if [ -z "$(git config github.token)" ]
then echo "warning: no api key found, to add follow instructions on github account page."
else echo "attempting to create a new gist using your github authentication..."; fi
SHA=$((curl https://gist.github.com/gists --include \
--data login=$(git config github.user) \
--data token=$(git config github.token) \
--data action_button=private \
--data 'file_ext[gistfile1]=txt' \
--data 'file_contents[gistfile1]=Hello World, this is an example gist!' \
| perl -e 'for(<>){if(/^Location: https?:\/\/gist.github.com\/([0-9a-f]+)/){print $1}}')2>/dev/null)
echo "New example gist created at https://gist.github.com/$SHA"
关于javascript - 使用 Github API 添加新 Gist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1992902/