PushSharp GCM "Authentication failed"

I've been using PushSharp for Apple notifications for a while on both a web service and a windows service without any problem.

When adding code for Google GCM, it works fine on my webservice and console application that I converted the service to, but it fails on windows service even when running on the same server (Amazon EC2 Instance)

The following code gives an "Authentication failed" error for GCM notification and has no error for Apple notification. However, if I run the same code in my webservice or console application on the same server, it works fine.

Dim push As PushBroker = New PushBroker

Try
        AddHandler push.OnNotificationSent, AddressOf NotificationSent
        AddHandler push.OnNotificationFailed, AddressOf NotificationFailed

        Dim appleCert = File.ReadAllBytes("FILENAME")
        push.RegisterAppleService(New ApplePushChannelSettings(False, appleCert, "PASSWORD"))
        push.RegisterGcmService(New GcmPushChannelSettings("API_KEY"))
        push.QueueNotification(New GcmNotification().ForDeviceRegistrationId("ANDROID-TOKEN").WithJson("{""alert"":""Hello World!"",""badge"":1,""sound"":""sound.caf""}"))
        push.QueueNotification(New AppleNotification().ForDeviceToken("IOS-TOKEN").WithContentAvailable(1))

    Catch ex As Exception

    End Try

      

If I remove the line:

   push.QueueNotification(New GcmNotification().ForDeviceRegistrationId("ANDROID-TOKEN").WithJson("{""alert"":""Hello World!"",""badge"":1,""sound"":""sound.caf""}"))

      

it works fine on both windows service and web service.

Can anyone see what I am doing wrong? This is not a firewall issue. I turned off the firewall and it still didn't work. I had a lot of other code and went over to the above code to make sure there were no hidden problems.

EDIT. I installed a console app by copying the code from a windows service and using the browser API key instead of the server API key.

This works fine on both my local machine and the server machine. However, the Windows service still gets the same error whichever API key I use.

UPDATE: Although the Windows service gets the error, it actually sends two notifications and then no more. If I stop the service and start it again, I get two more notifications, even if the notification error still returns.

I am really stuck. I can just run the console app all the time for now, but this is hardly ideal. Any help would be greatly appreciated.

+3


source to share


1 answer


I had a similar problem - everything worked fine in Visual Studio, but authentication on the production AndroidGcm server failed.

I figured it had to do with the IP list in Key for server applications, so I tried to restore it with my server IP. It didn't work.



Eventually, in response to one of the comments above and another thread elsewhere, I went into the Google Play developer console from the server and generated a new key without specifying IP addresses.

Using this key I fixed my problem

0


source







All Articles