(As of 2013-07-09)
Already two months ago, Google announced Google Cloud Messaging, which sends push notifications to Chrome extensions and the like. Maripo wrote the following article at an early stage.
I tried Google Cloud Messaging for Chrome
I wrote a demo that sends a Channel ID from the Chrome extension to GAE and sends a message from GAE to the sent ID, so I will write it for the time being.
In this article, I will write what I noticed when I tried GCM. In addition, since the author's web-based work technology is low, it would be helpful if you could tell me about the points that can be stingy in the above repository.
I will write about the above two projects at the end.
I had made a Chrome extension for a certain matter before, but I started by doing it again based on the original tutorial.
The extended registration itself has nothing to do with GCM at first glance, but it is used to get the channel ID. The channel ID is the destination that points to the Chrome extensions installed in each user's Chrome.
Click here for a quote from Honke:
Similar to an email address, the channel ID is used to identify and send messages to a specific user of your app or extension. Your app or extension needs to send this value to its application server so that the server can trigger push messages back.
I register on Google's server that realizes GCM, but at this time it costs $ 5 only once to register as a developer. It should also be effective when using APIs other than GCM. Most of the readers here think that this step was done a few years ago.
Then, upload the created extension as a zip. Of course, you can limit who can download. This time, I uploaded it in the form of Trusted Tester only == Virtually only myself.
https://chrome.google.com/webstore/developer/dashboard
I think it's basic, but when you upload a Chrome extension to Google Play, the changes don't take effect immediately. Specifically, it says:
The item is being published. It can take up to 60 minutes for it to appear on the Chrome Web Store.
Actually, it doesn't seem to take 60 minutes to be displayed, but it doesn't update in 1 second.
It's subtly annoying to always experience this lag during development, so it's a good idea to manually set the key as described later in Maripo's article. You can look up the key and manually embed it in manifest.json. If you are using google-chrome on Linux, there seems to be an extension under ~ / .config / google-chrome / Default / Extensions /, so you can pull out the key from it and put it in the one under development.
There are four things the Chrome extension must do to receive a message:
I have no choice but to write permissions in manifest.json, so I will do so.
If "Prepare channel ID" is an extension registered in the Chrome Web Store, you can get it by hitting the appropriate API (chrome.pushMessaging.getChannelId ()).
You need to create the "tell the channel ID to the server" part by yourself according to the form of the service you want to provide in the end. I implemented it this time as if it were sent when the popup was opened.
"Implementing a callback to receive a message" is not in the tutorial, but it can be done naturally by using the background mechanism.
There was no implementation example that works for this part, so I wrote it just in case, but it was not a big deal. However, there is something like a habit peculiar to Chrome extension, so I learned that.
The Google API Console finally gives you three pieces of information: These have no expiration date and seem to be usable forever.
From these three sets, you get a time-limited access token. This access token, channel ID (destination), and payload (message body) actually send the message to a specific extension.
Once from the head family.
You need two types of OAuth 2.0 tokens to authorize each call to the push messaging service: the refresh token and the access token. The access token authorizes each call to the service; however, this token expires after about an hour. The refresh token is used to 'refresh' the access token over time. These tokens are scoped to only send messages on behalf of your application or extension and nothing else.
The first three must be obtained manually via the Google APIs Console in advance, and the access token must be obtained again by the server as appropriate.
If you use the curl command to send messages manually, you don't need a server. You can get an access token from three types of information, client ID, client secret, and refresh token, and send a message using the access token and channel ID.
I wanted to link Chrome extension with GAE, so I wrote the server side as appropriate.
A button will be placed when you install the Chrome extension. When you press the button, the channel ID will be sent to the server. The server remembers the channel ID and can send a simple message to the browser extension that sent the channel ID.
In addition, when playing, you have to do at least the following work. It's a lot of trouble
It's also important because we don't give much consideration to security.
Recommended Posts