Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Play Developer Notification

I'm having difficulty setting up an end-point to receive Google Play Developer Notifications via Pub/Sub in a c# controller. I've set everything up against the app to publish to a topic and I have successfully setup a subscription in Google Pub/Sub...and the test notification is coming through on Google Pub/Sub...the problem is I am having trouble receiving the push notification on my server side c# controller end-point...I'm not sure how to set that up and if I have the correct json signature. I can't find any examples or documentation around this. Any help would be appreciated!

like image 299
Barry Theunissen Avatar asked Apr 16 '26 09:04

Barry Theunissen


1 Answers

This is my first "test" of Pub/Sub and this sample worked for me.

See all samples here: https://github.com/GoogleCloudPlatform/dotnet-docs-samples/tree/main/pubsub/api/Pubsub.Samples

These steps needs to be done:

  1. Create a topic here: https://console.cloud.google.com/cloudpubsub/topic/ , in the example we call it "iap"
  2. Under permission for "iap", add [email protected] as Pub/Sub publisher. This will allow Google Play to publish on this topic.
  3. Under subscriptions https://console.cloud.google.com/cloudpubsub/subscription add your service account/personal gmail or what ever that is linked to your c# server later on. I tested [email protected] and it worked fine. Check your environment variable "GOOGLE_APPLICATION_CREDENTIALS" and extract this user as Pub/Sub subscriber in permissions for "iap-sub".
  4. Play store needs to be configured under "Monetization setup". String are for instance: projects/yourproject/topics/iap
  5. Press a test message (you can also see it in the Cloud console)

Test message could look something like this:

20:16:07: Received message 6108129433484522 20:16:07: {"version":"1.0","packageName":"com.yourproject","eventTimeMillis":"1666642564858","testNotification":{"version":"1.0"}}

Class below runs the client in the background without waiting. If you just wanna try in a console, use the Console.ReadLine()

public class GCloudPubSub : IDisposable
{
    public String projectId { get; set; }
    public String subscriptionId { get; set; }

    private SubscriberClient _client;
    
    public FirebasePubSub() {
        projectId = "yourproject";
        subscriptionId = "iap-sub";
    }

    public async void Start() 
    {
        SubscriptionName subscriptionName = SubscriptionName.FromProjectSubscription(projectId, subscriptionId);
        _client = await SubscriberClient.CreateAsync(subscriptionName);
        await _client.StartAsync(HandleMessage);
    }

    public async void Stop()
    {
        await _client.StopAsync(CancellationToken.None);
    }

    public void Dispose()
    {
        Stop();
    }

    static Task<SubscriberClient.Reply> HandleMessage(PubsubMessage message, CancellationToken token)
    {
        Log($"Received message {message.MessageId}");

        string text = System.Text.Encoding.UTF8.GetString(message.Data.ToArray());

        Log(text);

        return Task.FromResult(SubscriberClient.Reply.Ack);
    }

    static void Log(string text) => Console.WriteLine($"{DateTime.UtcNow:HH:mm:ss}: {text}");
}

Hopefully this will lead you on the right way :)

like image 78
Large Avatar answered Apr 17 '26 21:04

Large



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!