[英]Add New Gist using the Github API
我正在Adobe Air制作一個小應用程序,我需要與Github Gist API進行交互。 但是我有點卡住了。
如果您不熟悉Adobe Air,您仍然可以提供幫助, XMLHttpRequest
javascript對象可以執行跨域請求,因為沒有這樣的域。 所以這里沒有Adobe Air的具體內容。
在我被困的地方,我想我需要對自己進行身份驗證然后進行POST。 我只是不明白
您的腳本的問題是,雖然您正在發送POST方法,但您正在將URL中的數據添加為GET。 您只需要將xmlhttp.send(NULL)
更改為xmlhttp.send(data)
,其中data
是您之前附加到gists
URL的查詢數據(包括文件和身份驗證信息)。
舉個簡單的例子,這里是一個創建新gist 的bash腳本的摘錄:
#!/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"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.