javascript - 使用 Github API 添加新 Gist

标签 javascript api air github

我正在 Adob​​e Air 中制作一个小应用程序,我需要与 Github Gist API 进行交互。但是我有点卡住了。

如果您不熟悉 Adob​​e Air,您仍然可以提供帮助,XMLHttpRequest javascript 对象可以执行跨域请求,因为没有这样的域。所以这里没有任何特定于 Adob​​e 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/

相关文章:

javascript - API 在 MVC 中扮演什么角色?

android - 无法在 Android 上调试 Adob​​e AIR 移动应用程序

ios - 在 Adob​​e Flash Pro 中设计的应用程序在 iOS 设备上的动画滞后

ios - 如何在 AS3 中使用 iOS 相机?

javascript - 类型错误 : invalid 'in' operand e in jquery 1. 10.2v

javascript - 如何删除链接中单词之间的空格?

javascript - 获取 promise 数组的大小( Protractor )

c# - 使用 Github api 违反协议(protocol)

php - PHP REST API 如何接收 PUTted 数据?

php - 如何在YouTube API浏览器上传表单中添加其他字段(并进行处理)?