ChimeraCoder / anaconda

A Go client library for the Twitter 1.1 API
MIT License
1.14k stars 247 forks source link

Panic when trying to get an AuthorizationURL #244

Closed perelin closed 6 years ago

perelin commented 6 years ago

Hi,

I´m trying to get an AuthorizationURL with anaconda but keep running into this:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1220c4f]

goroutine 1 [running]:
p2lab/twissr/vendor/github.com/ChimeraCoder/anaconda.(*TwitterApi).AuthorizationURL(0x0, 0x12b5f4c, 0x18, 0x129f780, 0x1, 0xc42000e050, 0xc420055f58, 0xc420055f78)
    /Users/perelin/code/go/src/p2lab/twissr/vendor/github.com/ChimeraCoder/anaconda/twitter.go:197 +0xff
main.main()
    /Users/perelin/code/go/src/p2lab/twissr/cmd/twittertest/main.go:16 +0x9f
exit status 2

Here is my full code snippet to reproduce

package main

import (
    "fmt"

    "github.com/ChimeraCoder/anaconda"
)

func main() {

    var api *anaconda.TwitterApi

    anaconda.SetConsumerKey("KEY")
    anaconda.SetConsumerSecret("SECRET")

    authURL, _, err := api.AuthorizationURL("http://CALLBACKURL")

    if err != nil {
        fmt.Println(err.Error())
    }

    fmt.Println(authURL)
}

go version go1.10 darwin/amd64

{
            "checksumSHA1": "LXwhuwfh4S+97nKVedaseJOhRIg=",
            "path": "github.com/ChimeraCoder/anaconda",
            "revision": "a1f48994eee061428eadcac94cf5fe98dbab0967",
            "revisionTime": "2018-03-05T15:13:39Z"
 }

Any ideas?

perelin commented 6 years ago

OK, stupid me. The anaconda API client needs to be initialized with personal Access Token + Secret as well. So, this works fine:

package main

import (
    "fmt"

    "github.com/ChimeraCoder/anaconda"
)

func main() {

    api := naconda.NewTwitterApiWithCredentials(ACCESS_TOKEN, ACCESS_TOKEN_SECRET, "your-consumer-key", "your-consumer-secret")

    authURL, _, err := api.AuthorizationURL("http://CALLBACKURL")

    if err != nil {
        fmt.Println(err.Error())
    }

    fmt.Println(authURL)
}