admin管理员组

文章数量:1025478

I have created a script that should get Mastodon Social status updates from my user. However when I post a new status I do not see it in my Go script.

For example I started my steam at 15:53, then created a new Mastodon Social Status at 15:54, but it did not come in to the terminal:

Here Is my Go code:

package main

import (
    "fmt"
    "github/gorilla/websocket"
    "log"
    "os"
)

func StreamPublicTimelineWebSocket(instanceURL string, token string) {
    // Mastodon Streaming WebSocket API URL
    url := fmt.Sprintf("wss://%s/api/v1/streaming/user", instanceURL)
    log.Printf("streaming timeline web socket url: %s", url)

    // Create a WebSocket dialer to manage the connection
    dialer := websocket.DefaultDialer

    // Create a map for custom headers if necessary (e.g., User-Agent)
    headers := map[string][]string{
        "User-Agent":    {"Mastodon Streamer Go"},
        "Authorization": {" Bearer " + token},
    }

    // Establish a WebSocket connection with custom headers
    conn, _, err := dialer.Dial(url, headers)
    if err != nil {
        log.Fatalf("Failed to connect to Mastodon streaming WebSocket: %v", err)
        os.Exit(1)
    }
    defer conn.Close()

    log.Printf("Successfully connected to stream at: %s", url)

    // Continuously read and process incoming WebSocket messages
    for {
        _, msg, err := conn.ReadMessage()
        if err != nil {
            log.Fatalf("Error reading WebSocket message: %v", err)
        }

        // Print out the received message (which is a Mastodon post)
        log.Printf("Received message: %s", msg)
    }
}

func main() {
    fmt.Println("Creating stream to Mastodon")

    // Stream
    token := "nk_HZ6......b2lDiI"
    instanceURL := "streaming.mastodon.social"

    // Start streaming the public timeline in real-time using WebSocket
    log.Println("Starting streaming from Mastodon...")
    StreamPublicTimelineWebSocket(instanceURL, token)

}

What is wrong? Why cant I get new statuses?

I have created a script that should get Mastodon Social status updates from my user. However when I post a new status I do not see it in my Go script.

For example I started my steam at 15:53, then created a new Mastodon Social Status at 15:54, but it did not come in to the terminal:

Here Is my Go code:

package main

import (
    "fmt"
    "github/gorilla/websocket"
    "log"
    "os"
)

func StreamPublicTimelineWebSocket(instanceURL string, token string) {
    // Mastodon Streaming WebSocket API URL
    url := fmt.Sprintf("wss://%s/api/v1/streaming/user", instanceURL)
    log.Printf("streaming timeline web socket url: %s", url)

    // Create a WebSocket dialer to manage the connection
    dialer := websocket.DefaultDialer

    // Create a map for custom headers if necessary (e.g., User-Agent)
    headers := map[string][]string{
        "User-Agent":    {"Mastodon Streamer Go"},
        "Authorization": {" Bearer " + token},
    }

    // Establish a WebSocket connection with custom headers
    conn, _, err := dialer.Dial(url, headers)
    if err != nil {
        log.Fatalf("Failed to connect to Mastodon streaming WebSocket: %v", err)
        os.Exit(1)
    }
    defer conn.Close()

    log.Printf("Successfully connected to stream at: %s", url)

    // Continuously read and process incoming WebSocket messages
    for {
        _, msg, err := conn.ReadMessage()
        if err != nil {
            log.Fatalf("Error reading WebSocket message: %v", err)
        }

        // Print out the received message (which is a Mastodon post)
        log.Printf("Received message: %s", msg)
    }
}

func main() {
    fmt.Println("Creating stream to Mastodon")

    // Stream
    token := "nk_HZ6......b2lDiI"
    instanceURL := "streaming.mastodon.social"

    // Start streaming the public timeline in real-time using WebSocket
    log.Println("Starting streaming from Mastodon...")
    StreamPublicTimelineWebSocket(instanceURL, token)

}

What is wrong? Why cant I get new statuses?

本文标签: