英文:
https://onesignal.com/api/v1//notifications: http.DefaultTransport and http.DefaultClient are not available in App Engine
问题
当我尝试在使用OneSignal环境的Golang App Engine中实现推送通知时,遇到了错误“App Engine中不可用http.DefaultTransport和http.DefaultClient”。这是我的代码:
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" // 有效的ID
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
}
// ...
}
希望这可以帮助到你!
英文:
When i tried to implement push notification in golang App Engine using onesignal enviorment.But iam getting error "http.DefaultTransport and http.DefaultClient are not available in App Engine".This is my code,
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
}
...
}
答案1
得分: 1
在App Engine上使用HTTP,你需要使用urlfetch。
https://cloud.google.com/appengine/docs/standard/go/urlfetch/reference
也就是说,你使用的包不支持App Engine。
英文:
Use http on appengine, you have to use urlfetch.
https://cloud.google.com/appengine/docs/standard/go/urlfetch/reference
i.e. the package you use doesn't support appengine.
答案2
得分: 1
Robby Colvin在这篇博客中解决了类似的问题。
它解释了如何在这种情况下运行第三方包。希望这对你有帮助。
英文:
A similar issue has been addressed by Robby Colvin in this blog
It explains how to make a third party package run in such conditions. Hoping this will help.
1: https://robbycolvin.com/google-app-engine-http-default-transport/ "Robby Colvin in this blog"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论