Coder Social home page Coder Social logo

Comments (8)

RasmusLindroth avatar RasmusLindroth commented on May 24, 2024 1

That works @RasmusLindroth. However, the AuthenticateToken() works only once. Reuse of the same code seems to be forbidden. Do you have an idea on how to reuse the code? I obviously don't want to register a new app each time I restart my tool

You just run AuthenticateToken() once, then you use:

conf := &mastodon.Config{
	Server:       acc.Server,
	ClientID:     acc.ClientID,
	ClientSecret: acc.ClientSecret,
	AccessToken:  acc.AccessToken,
}
client := mastodon.NewClient(conf)

Now you can use the client for your requests

from go-mastodon.

sbani avatar sbani commented on May 24, 2024 1

Wow, it's so easy. That works, thank you!

from go-mastodon.

mattn avatar mattn commented on May 24, 2024

Probably, your mastodon server stop to support grant_type=password.

from go-mastodon.

betandr avatar betandr commented on May 24, 2024

Ah, I've added some debug in go-mastodon and it yields: The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client

from go-mastodon.

betandr avatar betandr commented on May 24, 2024

Do you have a code example of using the mastodon.AuthenticateToken function?

from go-mastodon.

RasmusLindroth avatar RasmusLindroth commented on May 24, 2024

Do you have a code example of using the mastodon.AuthenticateToken function?

I'm on my phone so I can't write a good example. But checkout how I do it in tut.

Here's how I register a new account in my program.

https://github.com/RasmusLindroth/tut/blob/2634818c0a1097da935d7137b3620249e679223b/auth/add.go

To use the access token once you have generated it you'll just have to include it in your config like this.

conf := &mastodon.Config{
	Server:       acc.Server,
	ClientID:     acc.ClientID,
	ClientSecret: acc.ClientSecret,
	AccessToken:  acc.AccessToken,
}

from go-mastodon.

sbani avatar sbani commented on May 24, 2024

That works @RasmusLindroth. However, the AuthenticateToken() works only once. Reuse of the same code seems to be forbidden. Do you have an idea on how to reuse the code? I obviously don't want to register a new app each time I restart my tool

from go-mastodon.

ktpx avatar ktpx commented on May 24, 2024

The example on the main page fails.

c := mastodon.NewClient(&mastodon.Config{
Server: "https://mstdn.jp",
ClientID: "client-id",
ClientSecret: "client-secret",
})
err := c.Authenticate(context.Background(), "your-email", "your-password")
if err != nil {
log.Fatal(err)
}

atleast when i tried. Need to add accesskey and remove the authenticate part.

from go-mastodon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.