Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application token is invalid error with example code #25

Closed
tommyalatalo opened this issue Jul 10, 2022 · 3 comments
Closed

Application token is invalid error with example code #25

tommyalatalo opened this issue Jul 10, 2022 · 3 comments

Comments

@tommyalatalo
Copy link

tommyalatalo commented Jul 10, 2022

I've been using this module for some time in the past, but now I'm writing a new application that should send pushover notifications, and I keep getting errors saying application token is invalid, and I don't understand why.

I have tried to set API tokens that I know are working (and are currently in use by other applications), into my own code, as well as the example code in the readme for this repo, neither of these work and the error response from app.SendMessage is application token is invalid in both cases.

Has the pushover API changed, or is there something else going on here? I'm on go 1.18, tried on 1.17 with the same results.
If I go to the Pushover web UI I can successfully send messages to my new application / api token.
I also tried the cli applicationt ntfy which can send pushover messages, I set it to use my new api token and sent a message successfully. Judging from this it seems that either my Go setup or this module has a bug somewhere causing this error.

I am dumbfounded by how the below example code with my tokens returns the error mentioned above.
It would be great to begin by verifying that this code is still working with the module v1.1.0.

package main

import (
	"log"

	"github.com/gregdel/pushover"
)

func main() {
	// Create a new pushover app with a token
	app := pushover.New(<my known working user token>)

	// Create a new recipient
	recipient := pushover.NewRecipient(<my known working api token>)

	// Create the message to send
	message := pushover.NewMessage("Hello !")

	// Send the message to the recipient
	response, err := app.SendMessage(message, recipient)
	if err != nil {
		log.Panic(err)
	}

	// Print the response if you want
	log.Println(response)
}

@gregdel
Copy link
Owner

gregdel commented Jul 11, 2022

Hello @altosys,

First of all thanks for using this lib :)

The New function takes the API token and the NewRecipient function takes the user token. From the example of code above, it seems that you did it the other way around.
Can you try swapping the two tokens an try again ?

@tommyalatalo
Copy link
Author

Ah yes, this is the case, I swapped them. I was under the impression that pushover.New sets up a new object to manage the messages sent by my user key, and pushover.Recipient defines which of my applications to send to, I'd forgotten how this worked since setting it up last time a few years ago.

I assume that it's set up the way it is in order to be able to send to multiple user keys from the same api token.

Why I didn't just try swapping them yesterday is beyond me, I must have been incredibly tired...

@gregdel
Copy link
Owner

gregdel commented Jul 12, 2022

Glad I could help :)

@gregdel gregdel closed this as completed Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants