Add Google service credentials to Android App for connect Google Cloud - android

In my app I need to use Google Cloud Text to Speech. I add sdk via gralde
implementation 'com.google.cloud:google-cloud-texttospeech:0.100.0-beta'.
After that i am not understanding how to add credentials to my android app. In Cloud console I created and added billing for project and downloaded service account json file. But where can i add in android app ? If i run code without adding the app I'm getting an exception
" The Application Default Credentials are not available. They are
available if running in Google Compute Engine. Otherwise, the
environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined
pointing to a file defining the credentials. See
https://developers.google "

https://github.com/GoogleCloudPlatform/android-docs-samples/tree/master/speech/Speech
Here you can see how to add credentials
Below is a TTS sample project that I created with reference to Google Cloud STT
https://github.com/ivso0001/GoogleCloudTextToSpeech/tree/master

Related

Firebase invalid credentials on Android

That's my concern, currently I'm developing an application that uses Firebase. Recently my identifiers for Android no longer work, the error tells me that the App ID does not match, however I am using google-services.json provides from my firebase console after adding my android application with its SHA key- 1.
My file is inside android/app folder like Firebase want it.
I have no problem with my iOS application, everything works fine.
Do you think I should try to delete Android ID clients OAuth 2.0 from google cloud platform and try to recreate it ?
it works, delete and recreate everything works, because Firebase works independently : if you delete an app inside your firebase console, it doesn't delete it inside google cloud platform.

Getting error while enabling the Google Cloud Build API for my projects?

Before a few days i got mail.
Enable the Cloud Build API for your projects before April 20, 2020, to
ensure Cloud Function is built and deployed correctly.
Access the Cloud Build API link in the Cloud Console.
Select your project from the drop-down menu.
Click Continue to enable the Cloud Build API for the project. A box will appear in the lower-left corner to confirm the API is enabled.
After click i getting following error for some permission
This API cannot be enabled at the moment. You may lack appropriate permissions.
.
So, which type of permission required i need to enable this service ?
The specific permissions that a user needs to enable APIs for a GCP project are:
serviceusage.services.enable
servicemanagement.services.bind
If you are already the owner of your project, you shouldn't have to add the roles/servicemanagement.serviceConsumer role to your account to enable an API.
You also need to enable billing on the project before you can enable new APIs.
The error I was getting
This API cannot be enabled at the moment. You may lack appropriate
permissions.
The issue for me was I have multiple google / gmail accounts and when I changed deploy location I had to logout and then log back in:
firebase logout
and then log back in
firebase login
This was followed by opening browser and then selecting the appropriate google user to deploy application with.

Failed to detect whether we are running on Google Compute Engine

I am trying to use Google Cloud Speech recognition but I get this error
I/omputeEngineCredentials: Failed to detect whether we are running on
Google Compute Engine. W/System.err: java.io.IOException: The
Application Default Credentials are not available. They are available
if running in Google Compute Engine. Otherwise, the environment
variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a
file defining the credentials. See
https://developers.google.com/accounts/docs/application-default-credentials
for more information.
I set the environment variable from System Properties/Environment Variables/User variables and also I set the credentials manually using this guide.
I have searched every topic that is relevant to this, but I can't get it to work. What am I missing?
I faced this issue while connecting to Cloud Storage from local .Following are the steps I followed that worked for me:
Install Cloud SDK. Reference link:Cloud SDK
Follow all the steps to initialize the SDK.
Now ,create application default credentials by using the following command in the root directory of your application gcloud auth application-default login, by which google-cloud will automatically detect your credentials.
It is hard to say without access to logs and code, but probably you should start from debugging accesses to speech API from console directly.
gcloud auth activate-service-account --key-file=[PATH]
gcloud ml speech recognize 'gs://cloud-samples-tests/speech/brooklyn.flac' \ --language-code='en-US'
https://cloud.google.com/blog/products/ai-machine-learning/ml-explorer-talking-and-listening-with-google-cloud-using-cloud-speech-and-text-to-speech
Possible reasons are:
- API is disabled,
- credential you use doesn't contains permissions for ML.
- credential file path is wrong.

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 enable google analytics in Firebase project

I need to use Google analytics services in my app (android and ios). I created a project in Google API Console and imported it into Firebase for FCM services. But after that, I cannot link the Google project into Google Analytics and get configuration file. When I try to get configuration file and select app name, it jumps to Firebase console.
If I add Android or iOS in the Firebase project, the configuration file I got doesn't have google analytics info.
Anyone know how to solve this. I need to use Google Analytics in my app but not the Firebase analytics.
I also need to support both standalone Google Analytics SDK and Firebase Analytics, and I was finally able to find a solution in this Google Analytics Support answer (Analytics for mobile apps).
Google Analytics without Firebase:
Go to Google Analytics > Admin > Create new Property
Select Website, using your app name as Website Name, and optionally your company website as Website URL.
Back up to the Admin page.
For the Property you just created, in the right-most column (View), there should be an "All Website Data" view. Create a new View.
Select Mobile App, naming the view something appropriate, like "All Mobile Data".
Note: Property Settings will now contain a valid GA Tracking ID you'll need for client set-up.
Google Analytics with Firebase:
Create a Firebase project for your app.
Go to Google Analytics > Admin > Create new Property
Select Mobile App, then use the "Link to Firebase" dropdown to connect to the Firebase project you created in Step 1.
Keep in mind that while there is still a standalone, non-Firebase Google Analytics API to support legacy applications, Google is definitely pushing all new application-development over to Firebase APIs. My opinion is that this solution is mainly good for libraries that need to support new & legacy apps, or during a transitional period.
Refill and Re-enter your application name in App name field manually, so that you will not have to select the routing to the Firebase option and it will not take you to the firebase console.
It's a silly thing by google
TO go to enable or disable the api like map , drive and other of google apis from Firebase project go to this link and will see all api , hope this help.
1. If you don't have GoogleAnalytcs library in your project, get it.
You can use cocoapods: pod 'Google/Analytics'.
2. Get Tracking ID from https://analytics.google.com. If you have not created an analytics account yet, you can do it there:
3. Add this Tracking ID to GoogleService-info.plistwith key TRACKING_ID:
4. Configure the app:
// Configure tracker from GoogleService-Info.plist.
var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
5. Example - sending screenView:
func sendScreenView(name: String) {
let tracker:GAITracker = GAI.sharedInstance().defaultTracker as GAITracker
let build = GAIDictionaryBuilder.createScreenView().set(name, forKey: kGAIScreenName).build() as NSDictionary
tracker.send(build as [NSObject : AnyObject])
}
Note: Above procedure is for iOS, Android configurations should be similar.

Categories

Resources