Getting an API key to use with Google Cloud Messaging - android

I am developing an Android app and I'd like to start testing out push notifications. From a code perspective, I'm all set. My current challenge is that I simply do not know how to get a Google Cloud Messaging API key from Google.
There are loads and loads of tutorials and videos online showing how this can be done in about 10 seconds but Google has recently updated it's developer center and none of the tutorials seem to apply any more. The current process seems very cumbersome and not at all similar to what I've seen online.
I realize that this barely passes as a programming question (if at all) but there is no way that I'm going to even begin to be able to develop anything without an API key from Google.
Is someone able to point me in the right direction?

CommonsWare was right about three years ago (2013). This is a revision to his answer.
Note: Even if you have already enabled any services and have API keys this will still work.
Log in to Google Services with your google account. (This is not the same as the Google Console)
Click on Pick a Platform
Click on Enable services for Android
Fill out the app name and package name
Select Cloud Messaging. (Or any other service you want. You can come back to this later and add more)
Click on Generate Configuration Files
Boom. Right there on top in the Cloud Messaging card under Server API key
Also, you will want to download the google-services.json file and copy it to the app/ or mobile/ module directory in your Android project

but Google has recently updated it's developer center and none of the tutorials seem to apply any more
:: sigh ::
That's yet more work for my next book update...
The current process seems very cumbersome and not at all similar to what I've seen online.
Bearing in mind that I am already set up with keys, and therefore may be seeing somewhat different stuff than would somebody with no keys:
Step #1: Log into https://cloud.google.com/console with your Google account
Step #2: In the navigation on the left, go into "APIs & auth > APIs"
Step #3: Find "Google Cloud Messaging for Android" and click the "OFF" button next to it (note: this might involve then agreeing to additional terms of service)
Step #4: In the navigation on the left, go into "APIs & auth > Registered apps"
Step #5: Wait a really long time, apparently.
Step #6: Click the red REGISTER APP button.
Step #7: Give the app a name and choose Web Application, then click Register
Step #8: Click the "Server Key" section for your server key

Google has updated their api console recently to Google Cloud Console.
In short terms , you need to create an Android application and pick Accessing APIs via a web server. this service has a detailed guide for that

The easiest way to configure GCM API key and Sender ID, is to Google login with your account and continue the Wizard : https://developers.google.com/mobile/add :)

To get FCM (Firebase cloud messaging) key for a web app
login into Firebase
Create a new app by clicking the big 'Add Project' button
Wait a few seconds and watch the circle chase its tail
Click "Add Firebase to your web app "
Copy the api key

Related

Android - firebase cloud messaging, two apps in one firebase project

I have two android applications. I am using only one firebase project for both of them, with both applications included in it. So I have only one google-services.json with specified keys for both my applications. I am trying to use firebase cloud messaging and I am experiencing following problems:
When I want to test cloud messaging from firebase console I am able to choose to which appId I want to send a message. I have both applications installed on my device. Both are working normally. I have also released them to google play (alpha testing) and everything went well. I am able to download them from store normally. AppId should be set properly (how can I check that?). Problem is, that when I choose the first app in firebase console I am receiving notifications from both apps and when I choose the second app I am receiving nothing.
What can cause these problems? Do I need to create completely new firebase project for the second app, too? Or am I missing something?
If you need to see some code, let me know. At this point I don't know what piece of code could tell you more about my problem.
It looks like you have used same google service json file on both your apps. So thats why sending cloud notification for one app is received on both apps while in second case since no app has the json file for that there is no notification.
Go to your firebase project settings and download the google services file for both app ( you should first download one and move that file to desired project then download second services file).

Service account doesn't show up in Google Play Console after creation

From my Google Play console I linked a project. Then I created a service account. Still, when refreshing the console, it still says "There are no service accounts associated with your project."
Waited over 24 hours already. The purpose of all that is receipts validation.
Picture 1: a linked project:
Picture 2: service-account created:
I had the same problem, I fixed it this way:
When you create a service account in step 2, you need to select a role to grant this service account some permissions, although it shows the step is optional, but for some cases, it's not. If you skip this step, the newly created service account will not show up at the Google Play Console API access page, and you will get this error message, The current user has insufficient permissions to perform the requested operation when you run your code.
You much enable "Google Play Android Developer API" (one of Google Api & services) for your application via a credential!
Google supplies many API for developers can call them from their app. A credential same as a permit (3 types of credentials : API key (such as youtube), OAuth, Service Account)
If you never enable one API, it never shown on API Access page!
In my case:
Even if you have created a service account,
When you have already deleted the service account with the same name,
It appears to have been deleted from the IAM tab of Google Cloud Platform.
So it is assumed that it is not visible in the play console.
TODO:
Create a service account with a different name (I gave the owner permission in step2 when creating, Like Q Locker's answer.).
After creation, it was immediately exposed in the play console.
I faced the same issue because I selected a wrong project instead of the project for which the service account to be created. Please double check the project name in the drop-down at top of the page (after going to the link of Google Cloud Platform). By default the right project to be selected automatically. But if no project is selected beforehand and you are asked to select a project, then select the right project carefully. Otherwise the service account won't show up after completing the whole process.
Another thing to mention, although the project is supposed to be selected automatically, initially it didn't happen and I was given the available projects to select from. The project may appear in the recent projects, otherwise click the SELECT PROJECT link and find yourself.
Moreover when I additionally logged out and removed all the other Google accounts from the browser except the account which is used in Google Play Console. That time I was redirected to service account creation page with the correct project selected beforehand.
Make sure the project name on screen 1 and screen 2 are the same. In my case project name were different.
Screen 1: Main API Access page on Google Console
Screen 2: Google Cloud Platform page

Which is the best way to make my rails project an AndroidPublisher Client? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I need to see the sales stats of my Android App in my CRM (in Rails), some people suggest me to use the Google API but I’m confused with all the documentation. Which is the best way to make my CRM an Android Client?
1. Upload your app to Google Play Console
If you haven’t uploaded your app to Play Store, you can follow the next guide. https://support.google.com/googleplay/android-developer/answer/113469?hl=en
When you create a project, Play Console link your project with a new project at Google Developers Console (Google Play and Google Developers Consoles are different, Play is to manage your apps in Play Store and Developer is to manage the applications and services that you are running in the Google Cloud) so only be sure that your Play Console is linked to a project in Google Cloud visiting in your Google Play Console Dashboard -> Settings(Developer Account) -> API Access -> Linked Project
Check the Linked Project section a and if the button shows UNLINK means Google Play Android Developer it’s ready.
If you want to manage your Google Cloud Project since console (For test real-time notifications you need this step) install gcloud on your computer https://cloud.google.com/sdk/downloads
2. Create users and grant permissions to your Rails Project
To give access to your rails application you could create a Service Account Credential that is a JSON file you need to set in your application, so every time you need to use the Google API with the Service Account you can create a token that gives you access to the data stored in Google Play. This token expires every 60 minutes so you can restore automatically every 1 hour with a cron or create a method to restore it every time you need access to Google API and the token had expired. (In the example client is working the second option)
Before creating any credential, check if the Cloud Project selected is the one for which you need the credentials, you can check it in the topbar aside Google Logo is the dropdown to select the project you want to work.
Confirming your project, create your Service Account follow this guide: https://developers.google.com/android/management/service-account
Store your JSON in a secure place or in your rails application, only don't forget to gitignore it if you are using git.
Then go to your Google Play Console to Dashboard->Settings->API Access in the Service Accounts section you will see a service with the same name than the one you give to your Service Account in Cloud Console and a blue button with the legend "GRANT ACCESS" press it set the permissions you want to give to that service, if it’s the first time you create services give Administrator permissions only to test, then if you know the limits of your client you can change the permissions of the Service Account in any moment.
After all above, you could pull data from Play Console with code like this
require 'google/apis/androidpublisher_v2'
Androidpublisher = Google::Apis::AndroidpublisherV2
scopes = Androidpublisher::AUTH_ANDROIDPUBLISHER
authorization = Google::Auth.get_application_default(scopes)
publisher = Google::Apis::AndroidpublisherV2::AndroidPublisherService.new
publisher.authorization = authorization
publisher.authorization.fetch_access_token!
//Using Android Publisher Api get the details of a product of your app.
#product_info = publisher.get_in_app_product(params[:package]
, params[:sku])
As you see in the last code, to get the data of a product you need to require the library AndroidPublisherV2 from Google API, so you need to put in your gemfile this:
gem 'google-API-client', '~> 0.9'
You could check the methods available in the library at http://www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/AndroidpublisherV2
To learn more about Google Authentication you could visit the next links:
https://developers.google.com/identity/protocols/application-default-credentials
https://github.com/google/google-auth-library-ruby
3. Configure Google Sub/Pub as webhook
If you want to receive real-time notifications when a user acquires a subscription in your Android App using InAppBilling, you will need to use the SUB/PUB Service of Google Cloud Platform.
To begin to follow this guide: https://cloud.google.com/pubsub/docs/quickstart-console
After finishing the guide, if you got an error like
ERROR: (gcloud.beta.pubsub.subscriptions.pull)
NOT_FOUND: Resource not found (resource=realtime-subs).
Probably your gcloud configuration at console is running in a different project, so only use
> gcloud init
And set default the project where you create the SUB/PUBs.
Then continue with the next tutorial to assign permissions and link your Android App notifications with the SUB/PUB subscription.
https://developer.android.com/google/play/billing/realtime_developer_notifications.html
To pull the test notification in your console you can type this in your console:
> gcloud beta pubsub subscriptions pull <subscription-name>
You will identify the notification of Android with the "packageName" value.
Now you need to create a SUB/PUB subscription that will push all the notifications that receive the topic to a callback end-point in your rails application.
First of all, the domain you will use in your callback needs to be registered in Google Domains to assure that you are the owner of that domain. Visit https://console.cloud.google.com/apis/credentials/domainverification
And select the tab Add Domain, just follow the steps that the process show you.
If your rails application is in localhost you could use ngrok to assign an URL, only consider that every time you restart ngrok the URL changes and you will need to do the Domain Verification for the new URL.
After that, go to https://console.cloud.google.com/cloudpubsub/ and create a new Subscription with the Delivery Type of Push into an endpoint URL and set your callback URL with https in the domain (even if you haven’t set up https in your domain it will work but avoid this practice if you are in production, please go an set up an SSL in your domain)
Now your Rails Application will get every notification that your app send to your topic in Google Cloud Platform.
A client sample in Sinatra is available as example of ruby client.

How to get the Browser Key for GCM as per the latest Developer Console?

I want to get the GCM Browser Key in the Developer Console, but the latest Developer Console doesn'tshow the Browser Key selection.
If I click Credentials, it doesn't show anything apart from one single key. I don't know what is the procedure to get the Browser key.
If anyone knows let solve my problem. Thanks in Advance.
You need to go to Google Developer Console and follow this steps:
Create Project
Enable Library
Create Credential (*)
(*) when u create credential, click on Restrict Key and add your specific Key restriction.
Update: There is now a visible note in the GCM docs saying:
Starting from Sept. 2016 new server key can only be created in the Firebase Console using the Cloud Messaging tab of the Settings panel. Existing projects that need to create a new server key can be imported in the Firebase console without affecting their existing configuration.
Update: It seems that using the Server Keys from the Firebase Console is the sure thing solution.
If you are just starting to use GCM, instead of creating a project in the Google Developers Console, do it in the Firebase Console. After creating the project, simply use the auto-generated Server Key. Here are the steps where to find the Server Key:
Go to your Firebase Console and click on CREATE NEW PROJECT.
Fill in your desired Project Name and select your Country. After this, the new Project should be active.
Then on left-side panel, click on the gear button and select Project Settings.
Then go to the Cloud-Messaging Tab.
For old GCM projects, you can simply Import the project to the Firebase Console:
Go to your Firebase Console and click on IMPORT PROJECT.
Select the project you want to import and your country.
Click on ADD FIREBASE. After this, the new Project should be active.
Then on left-side panel, click on the gear button and select Project Settings.
Then go to the Cloud-Messaging Tab.
Basing from the image, you've already generated an API Key. But gonna include the steps for visibility:
Go to your Google Developers Console
On the left-pane, click on Credentials
Under the Credentials Tab, Click on Create Credentials
Select API Key
With that, the API Key is already available. However, it will default as a No Restriction key. You may click on Restrict Key to add the restriction corresponding to what you need the API Key for.
I'm not entirely sure, but for a Browser Key, I think you would need to set the HTTP referrers (web sites) restriction. Since basing from the other restrictions:
IP addresses (web servers, cron jobs, etc.) = Server Key
Android apps = Android Key
iOS apps = iOS Key
You may try the API Key generated without any restrictions, however, it is highly encouraged for you to add the corresponding restriction as a security measure against unauthorized usage and quota theft.

can not create Android client id

My apologies for asking this question on Stackoverflow, but Google says that this is my only choice. I have a support package from Google in theory, but all attempts to get a PIN yield "Invalid Operation" (a different problem).
I am just trying to use the Google web page instructions to create an Android client Id for secure access to AppEngine Endpoints.
In the following Google instructions, steps 6 and 7 point me to non-existent user choices on the Google Cloud console.
Straight from the web page:
[https://developers.google.com/appengine/docs/java/endpoints/auth#Java_Creating_OAuth_20_client_IDs]
...
Creating an Android client ID
...
Open the Google Cloud Console. [https://cloud.google.com/console]
When your project appears in the projects pulldown menu, select it to make it the active project. [Selected the project from the table of projects]
Click APIs and Auth and select Registered Apps [No such selections exist; tried all links - nothing even close to on topic.]
If your app is not yet registered, select the Register App button. [No such link exists.]
…
I hope Google is listening and can help. My apologies to everyone else. I have no other way to contact Google.
I don't understand what's the issue, as the instruction provided is correct and that's how we generated the client ID for our projects:

Categories

Resources