javascript – 使用Github API添加新Gist

前端之家收集整理的这篇文章主要介绍了javascript – 使用Github API添加新Gist前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在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创建一个新要点的摘录:

  1. #!/usr/bin/env bash
  2. if [ -z "$(git config github.token)" ]
  3. then echo "warning: no api key found,to add follow instructions on github account page."
  4. else echo "attempting to create a new gist using your github authentication..."; fi
  5.  
  6. SHA=$((curl https://gist.github.com/gists --include \
  7. --data login=$(git config github.user) \
  8. --data token=$(git config github.token) \
  9. --data action_button=private \
  10. --data 'file_ext[gistfile1]=txt' \
  11. --data 'file_contents[gistfile1]=Hello World,this is an example gist!' \
  12. | perl -e 'for(<>){if(/^Location: https?:\/\/gist.github.com\/([0-9a-f]+)/){print $1}}')2>/dev/null)
  13.  
  14. echo "New example gist created at https://gist.github.com/$SHA"

猜你在找的JavaScript相关文章