2017-06-28 2 views
0

私は、oneignal環境を使用してgolang App Engineでプッシュ通知を実装しようとしましたが、エラーが発生しましたAppEngineの上使用します。httphttps://onesignal.com/api/v1//notifications: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 
    } 
    ... 
} 

答えて

1

、.Thisは私のコードである "http.DefaultTransportとhttp.DefaultClientはApp Engineの中では使用できません"、あなたはUrlFetchのを使用する必要があります。

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

つまり、あなたが使用したパッケージは、AppEngineのをサポートしていません。

+0

パッケージアプリエンジンを互換にする方法はありますか?パッケージはonesignalを使用してプッシュ通知を送信するためのものです –

+1

@farsanapb urlfetchは次のようにコンテキストを渡すべきです: 'c:= appengine.NewContext(r)' この 'r'はリクエストオブジェクトです。したがって、NewXXX用のcontext.Contextを追加することは私にとっては良い考えです。 – mattn

1

同様の問題は、それはそのような状態で実行するサードパーティ製のパッケージを作成する方法について説明しRobby Colvin in this blog

によって対処されています。これが助けになると願っています。

関連する問題