With v0.0.4, we assume that an AccessToken is set and use it to set an Authorization header in the request. With an empty AccessToken, this leads to an authorization error.
Omitting the entire header in that case fixes the problem. The following programm illustrates it.
package main
import (
"context"
"log"
mastodon "github.com/mattn/go-mastodon"
)
const serverURL = "https://mastodon.social"
func main() {
ctx := context.Background()
client := mastodon.NewClient(&mastodon.Config{
Server: serverURL,
})
q, err := client.StreamingPublic(ctx, false)
if err != nil {
log.Fatalf("StreamingPublic failed: %v", err)
}
for e := range q {
switch event := e.(type) {
case *mastodon.UpdateEvent:
log.Printf("UpdateEvent: account %s", event.Status.Account.URL)
case *mastodon.NotificationEvent:
log.Printf("NotificationEvent: type %#v", event.Notification.Type)
case *mastodon.ErrorEvent:
log.Printf("ErrorEvent: %#v", event)
}
}
}
The purpose of this PR is to enable anonymous (unauthenticated) streaming.
This curl command demonstrates that streaming works (at least on some instances) without a need for authentication.
With v0.0.4, we assume that an AccessToken is set and use it to set an
Authorization
header in the request. With an empty AccessToken, this leads to an authorization error.Omitting the entire header in that case fixes the problem. The following programm illustrates it.