0

I'm currently working with a Soundcloud wrapper for Go, I want to print the user's followers but it is the first time I face pointer issues.

After building error

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x10 pc=0xc9c26]

Code

package main

import (
    "fmt"
    "github.com/njasm/gosoundcloud"
)


func main() {
    //  callback url is optional - nil in example
    s, _ := gosoundcloud.NewSoundcloudApi("Client_Id", "Client_Secret", nil)
    var userID uint64 = 1
    member, err := s.GetUser(userID)
    if err != nil {
               panic(err)
     }
    fmt.Println(member.Followers)
}

After building

goroutine 1 [running]:
panic(0x3508c0, 0xc82000a0b0)
    /usr/local/go/src/runtime/panic.go:481 +0x3e6
net/http.(*Client).doFollowingRedirects(0x0, 0xc8200d0000, 0x4611c8, 0x0, 0x0, 0x0)
    /usr/local/go/src/net/http/client.go:429 +0x66
net/http.(*Client).Do(0x0, 0xc8200d0000, 0x8, 0x0, 0x0)
    /usr/local/go/src/net/http/client.go:188 +0xff
github.com/njasm/gosoundcloud.(*SoundcloudApi).do(0xc8200c8720, 0xc8200d0000, 0xc820012f00, 0x0, 0x0)
    /Users/ManuelDao/Documents/GoBot/src/github.com/njasm/gosoundcloud/soundcloud.go:217 +0x4b
github.com/njasm/gosoundcloud.(*SoundcloudApi).Get(0xc8200c8720, 0xc820012f00, 0x22, 0x0, 0x1, 0x0, 0x0)
    /Users/ManuelDao/Documents/GoBot/src/github.com/njasm/gosoundcloud/soundcloud.go:92 +0xe1
github.com/njasm/gosoundcloud.(*SoundcloudApi).GetUser(0xc8200c8720, 0x1, 0x417a80, 0x0, 0x0)
        /Users/ManuelDao/Documents/GoBot/src/github.com/njasm/gosoundcloud/soundcloud.go:276 +0xc6
main.main()
        /Users/ManuelDao/Documents/GoBot/src/GoBot/GoBot.go:24 +0x70
exit status 2

1 Answer 1

1

I've never used this lib before, but it looks like you forgot to authenticate yourself.

s, _ := gosoundcloud.NewSoundcloudApi("Client_Id", "Client_Secret", nil)
if err = s.PasswordCredentialsToken("[email protected]", "your_password"); err != nil {
    // handle err
}

Something like this maybe?

Sign up to request clarification or add additional context in comments.

5 Comments

Not really, to get the data it shouldn't be necessary to login with the api. Here's a link to the library godoc.org/github.com/njasm/gosoundcloud
Well, I just tried out your exact example and it fails with the same nil pointer error. After getting the token with PasswordCredentialsToken everything worked fine. I've checked the example at github.com/njasm/gosoundcloud
I plugged in your code and it tells me err not defined, I'm relatively new at Go. How did you handled the error?
Well... if there is no error then there is no error! :) In theory your code shouldn't panic now, have you tried it? Edit: if you plugged in the same exact code, then err is only defined within the if's scope.
Yes John! I tried it before commenting, I got at line 12 undefined: err

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.