Skip to content
Advertisement

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

I’m currently working on a Golang website (running on Ubuntu) that will update a twitter status. I used twurl customer key authentication on the system and I can successfully update the status if I type directly into the linux terminal. For example

  1. ssh/putty into target system
  2. type in terminal: twurl -d ‘status=is this thing on’ /1.1/statuses/update.json
  3. twitter status successfully updated

When I try to do the same through Golang exec, twitter gives me an authentication error.

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

I’ve tried a couple of different methods for formatting the statusarg. Printing the above statusarg to the console shows: ‘status=Windows worked, Testing update on ubuntu.’

Twurl does seem to be run as out shows an error response from twitter, {“code”:32,”message”:”Could not authenticate you.”}. I suspect it has to do with the setup of the command…??? Or maybe the interpretation of the single quotes in the status argument???

Advertisement

Answer

Don’t include the single quotes:

statusarg := "status=" + status

In Golang, "twurl" is a string containing twurl. In particular, the string data does not include the double quotes. Those quotes are just Go syntax for strings.

In Bash, 'status=Foo' is a string containing status=Foo. In particular, the string data does not include the single quotes. Those are just Bash syntax for uninterpolated strings.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement