为什么此 twurl 命令(运行 on linux,由 golang exec 执行)未通过身份验证?

Why is this twurl command (run on linux, by golang exec) not being authenticated?

我目前正在开发一个 Golang 网站(运行ning on Ubuntu),该网站将更新 Twitter 状态。我在系统上使用了 twurl 客户密钥身份验证,如果我直接在 linux 终端中输入,我可以成功更新状态。例如

  1. ssh/putty进入目标系统
  2. 在终端中输入:twurl -d 'status=is this thing on' /1.1/statuses/update.json
  3. 推特状态更新成功

当我尝试通过 Golang exec 执行相同操作时,twitter 给我一个身份验证错误。

func UpdateMainStatus(status string) {
    statusarg := `'` + "status=" + status + `'`
    out, err := exec.Command("twurl", "-d", statusarg, "/1.1/statuses/update.json").Output()
}

我尝试了几种不同的方法来格式化 statusarg。将上面的 statusarg 打印到控制台显示:'status=Windows worked, Testing update on ubuntu.'

Twurl 似乎确实是 运行,因为它显示了来自 Twitter 的错误响应,{"code":32,"message":"Could not authenticate you."}。我怀疑这与命令的设置有关...???或者可能是状态参数中单引号的解释???

不要包含单引号:

statusarg := "status=" + status

在Golang中,"twurl"是一个包含twurl的字符串。特别是,字符串数据不包括双引号。这些引号只是字符串的 Go 语法。

在Bash中,'status=Foo'是一个包含status=Foo的字符串。特别是,字符串数据不包括单引号。这些只是未插值字符串的 Bash 语法。