下面直接贴代码,附带源码和成品,请自行下载
package main
import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"time"
)
type structureData struct {
StatusCode int `json:"status_code"`
UserInfo struct {
AwemeCount int `json:"aweme_count"`
FollowingCount int `json:"following_count"`
SecUID string `json:"sec_uid"`
EnterpriseVerifyReason string `json:"enterprise_verify_reason"`
IsMixUser bool `json:"is_mix_user"`
UID string `json:"uid"`
Nickname string `json:"nickname"`
AvatarLarger struct {
URI string `json:"uri"`
URLList []string `json:"url_list"`
} `json:"avatar_larger"`
OriginalMusician struct {
MusicCount int `json:"music_count"`
MusicUsedCount int `json:"music_used_count"`
DiggCount int `json:"digg_count"`
} `json:"original_musician"`
Signature string `json:"signature"`
FavoritingCount int `json:"favoriting_count"`
UniqueID string `json:"unique_id"`
MixInfo interface{} `json:"mix_info"`
AvatarMedium struct {
URI string `json:"uri"`
URLList []string `json:"url_list"`
} `json:"avatar_medium"`
VerificationType int `json:"verification_type"`
TypeLabel interface{} `json:"type_label"`
TotalFavorited string `json:"total_favorited"`
MplatformFollowersCount int `json:"mplatform_followers_count"`
IsGovMediaVip bool `json:"is_gov_media_vip"`
ShowFavoriteList bool `json:"show_favorite_list"`
CardEntries []interface{} `json:"card_entries"`
ShortID string `json:"short_id"`
FollowStatus int `json:"follow_status"`
FollowerCount int `json:"follower_count"`
Secret int `json:"secret"`
Geofencing interface{} `json:"geofencing"`
PolicyVersion interface{} `json:"policy_version"`
AvatarThumb struct {
URI string `json:"uri"`
URLList []string `json:"url_list"`
} `json:"avatar_thumb"`
CustomVerify string `json:"custom_verify"`
PlatformSyncInfo []interface{} `json:"platform_sync_info"`
FollowersDetail interface{} `json:"followers_detail"`
MixCount int `json:"mix_count"`
} `json:"user_info"`
Extra struct {
Now int64 `json:"now"`
Logid string `json:"logid"`
} `json:"extra"`
}
func main() {
for {
fmt.Println(`
韩昊杰go语言软件
查询抖音信息工具
输入quit即可退出
`)
var scan string
fmt.Print("请输入你要查询用户的ID:")
reader := bufio.NewReader(os.Stdin) // 标准输入输出
scan, _ = reader.ReadString('\n') // 回车结束
scan = strings.TrimSpace(scan) // 去除最后一个空格
if scan == "quit" {
os.Exit(1)
}
fmt.Println("------------------------------下面是结果------------------------------")
fmt.Println("")
returnData := request(scan)
fmt.Printf("账号昵称:%v\n", returnData.UserInfo.Nickname)
fmt.Printf("短位id:%v\n", returnData.UserInfo.UID)
fmt.Printf("获赞数量:%v\n", returnData.UserInfo.TotalFavorited)
fmt.Printf("粉丝:%v\n", returnData.UserInfo.FollowerCount)
fmt.Printf("关注:%v\n", returnData.UserInfo.FollowingCount)
fmt.Printf("签名:%v\n", returnData.UserInfo.Signature)
fmt.Printf("头像链接:%v\n", returnData.UserInfo.AvatarLarger.URLList[0])
fmt.Println("")
fmt.Println("------------------------------上面面是结果------------------------------")
time.Sleep(time.Second * 4)
fmt.Println("再次输入内容即可再次查询")
}
}
func request(data string) structureData {
resp, err := http.Get("https://www.iesdouyin.com/web/api/v2/user/info/?unique_id=" + data)
if err != nil {
fmt.Print("http faild err data:", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Print("ioutil faile")
}
var returnData structureData
json.Unmarshal([]byte(body), &returnData)
return returnData
}
还能用吗