[英]Stuck on “authorizationsStateWaitPhoneNumber” status with go-tdlib
我正在使用go-tdlib收集 Telegram 中的消息。 我嘗試修改示例。 當我第三次重新啟動服務時。 它停止工作。 所以我打印了這些消息。 它不斷給我authorizationsStateWaitPhoneNumber
狀態。 我什至無法在控制台中輸入我的電話號碼。 下面是代碼:
package main
import (
"fmt"
"log"
"math"
"os"
"os/signal"
"syscall"
"time"
"github.com/Arman92/go-tdlib"
"github.com/joho/godotenv"
)
const (
MaxAttempt = 10
)
var (
apiID string
apiHash string
)
var allChats []*tdlib.Chat
var haveFullChatList bool
func main() {
log.Println("Start Service")
log.Printf("API ID: %+v\n", apiID)
log.Printf("API HASH: %+v\n", apiHash)
tdlib.SetLogVerbosityLevel(1)
tdlib.SetFilePath("./errors.txt")
// Create new instance of client
client := tdlib.NewClient(tdlib.Config{
APIID: apiID,
APIHash: apiHash,
SystemLanguageCode: "en",
DeviceModel: "Server",
SystemVersion: "1.0.0",
ApplicationVersion: "1.0.0",
UseMessageDatabase: true,
UseFileDatabase: true,
UseChatInfoDatabase: true,
UseTestDataCenter: false,
DatabaseDirectory: "./tdlib-db",
FileDirectory: "./tdlib-files",
IgnoreFileNames: false,
})
log.Println("Starting auth")
// Wait while we get AuthorizationReady!
// Note: See authorization example for complete authorization sequence example
currentState, err := client.Authorize()
if err != nil {
log.Fatalf("Authorize error: %+v\n", err)
}
attempt := 0
for ; currentState.GetAuthorizationStateEnum() != tdlib.AuthorizationStateReadyType; currentState, err = client.Authorize() {
if err != nil {
log.Fatalf("Authorize error: %+v\n", err)
}
fmt.Printf("Current auth state: %+v\n", currentState)
attempt += 1
time.Sleep(5000 * time.Millisecond)
}
// get at most 1000 chats list
if err = getChatList(client, 1000); err != nil {
log.Fatalf("Error occurred in getChatList, msg: %+v\n", err)
}
log.Printf("got %d chats\n", len(allChats))
for _, chat := range allChats {
log.Printf("Chat title: %s \n", chat.Title)
}
signalTermination()
}
// see https://stackoverflow.com/questions/37782348/how-to-use-getchats-in-tdlib
func getChatList(client *tdlib.Client, limit int) error {
if !haveFullChatList && limit > len(allChats) {
offsetOrder := int64(math.MaxInt64)
offsetChatID := int64(0)
var lastChat *tdlib.Chat
if len(allChats) > 0 {
lastChat = allChats[len(allChats)-1]
offsetOrder = int64(lastChat.Order)
offsetChatID = lastChat.ID
}
// get chats (ids) from tdlib
chats, err := client.GetChats(tdlib.JSONInt64(offsetOrder),
offsetChatID, int32(limit-len(allChats)))
if err != nil {
return err
}
if len(chats.ChatIDs) == 0 {
haveFullChatList = true
return nil
}
for _, chatID := range chats.ChatIDs {
// get chat info from tdlib
chat, err := client.GetChat(chatID)
if err == nil {
allChats = append(allChats, chat)
} else {
return err
}
}
return getChatList(client, limit)
}
return nil
}
func signalTermination() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
<-c
}
func init() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
apiID = os.Getenv("TELEGRAM_API_ID")
apiHash = os.Getenv("TELEGRAM_API_HASH")
}
有沒有人遇到過這個問題? 我究竟做錯了什么?
我用這個例子更改了身份驗證過程,它起作用了!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.