gpt4 book ai didi

google-app-engine - https ://onesignal. com/api/v1//notifications : http. DefaultTransport 和 http.DefaultClient 在 App Engine 中不可用

转载 作者:数据小太阳 更新时间:2023-10-29 03:04:30 26 4
gpt4 key购买 nike

当我尝试使用 onesignal 环境在 golang App Engine 中实现推送通知时。但是我收到错误“http.DefaultTransport 和 http.DefaultClient 在 App Engine 中不可用”。这是我的代码,

func (c *PushNotificationController) CreateNotification() {
client := onesignal.NewClient(nil)
client.AppKey = "MyAppKey"
client.UserKey = "MyUserKey"
notifID := CreateNotifications(client)
log.Println(notifID)
}

func CreateNotifications(client *onesignal.Client) string {
playerID := "SamplePlayerId" // valid
notificationReq := &onesignal.NotificationRequest{
AppID: "MyAppKey",
Contents: map[string]string{"en": "English message"},
IsIOS: true,
IncludePlayerIDs: []string{playerID},
}
if createRes, res, err := client.Notifications.Create(notificationReq){
if err != nil {
log.Fatal(err)
}
return createRes.ID
}
...
}

最佳答案

在appengine上使用http,你必须使用urlfetch。

https://cloud.google.com/appengine/docs/standard/go/urlfetch/reference

即您使用的包不支持应用引擎。

关于google-app-engine - https ://onesignal. com/api/v1//notifications : http. DefaultTransport 和 http.DefaultClient 在 App Engine 中不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44796124/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com