GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — SpeechAPI samples and docs do not show how to pass credentials · Issue #697 · GoogleCloudPlatform/java-docs-samples

SpeechAPI samples and docs do not show how to pass credentials #697

New issue
Copy link
New issue
Copy link
Closed
Closed
SpeechAPI samples and docs do not show how to pass credentials#697
Copy link
Assignees
frankyn

Description

@redserpent7
redserpent7
opened on Jun 11, 2017
Issue body actions

I am trying to do some test using the Google Speech API but from outside Google Cloud. In the older beta version I was able to specify a credentials file but now I am unable to find this option in the SpeechClient class.

How can I go about specifying the authentication keys using the Google Speech API Java library? I believe a sample code should be added to demonstrate this (both passing flat credentials and using a credentials file)

P.S I already asked the same exact question on SO but 4 days later and still no one answered

Reacted by Swapnil Sawant and Jimi Wang

Activity

  1. frankyn commented on Jun 13, 2017

    @frankyn
    frankyn
    on Jun 13, 2017
    Contributor
    More actions

    Hi @redserpent7,

    Thanks for reaching out!

    You can authenticate using a service-account and setting the environment variable:
    export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json

    Instructions on creating a service account and setting the environment variable can be found at:
    https://cloud.google.com/docs/authentication/getting-started

  2. frankyn commented on Jun 15, 2017

    @frankyn
    frankyn
    on Jun 15, 2017
    Contributor
    More actions

    @redserpent7 did this help?

  3. frankyn
    self-assigned this
    on Jun 15, 2017
  4. redserpent7 commented on Jun 18, 2017

    @redserpent7
    redserpent7
    on Jun 18, 2017
    Author
    More actions

    @frankyn thanks but I am really interested in setting the credentials path as a configuration variable. Namely I want to do the exact same thing described here but in Java

  5. frankyn commented on Jun 19, 2017

    @frankyn
    frankyn
    on Jun 19, 2017
    Contributor
    More actions

    @gguuss do you know how to set credentials programmatically?

  6. frankyn commented on Jun 19, 2017

    @frankyn
    frankyn
    on Jun 19, 2017
    Contributor
    More actions

    @redserpent7, I was able to set credentials using the following flow. I'd still like your input @gguuss when you have a moment.

    CredentialsProvider credentialsProvider = FixedCredentialsProvider.create(ServiceAccountCredentials.fromStream(new FileInputStream("/path/to/service-account.json")));
    
    ChannelProvider channelProvider = SpeechSettings.defaultChannelProviderBuilder().setCredentialsProvider(credentialsProvider).build();
    
    SpeechSettings settings = SpeechSettings.defaultBuilder().setChannelProvider(channelProvider).build();
    
    // Instantiates a client
    SpeechClient speech = SpeechClient.create(settings);
    Reacted by tamirmich, hua21best, ShemerKuznits and Owen Gallagher
  7. gguuss commented on Jun 19, 2017

    @gguuss
    gguuss
    on Jun 19, 2017
    Contributor
    More actions

    @frankyn -- you're doing it correctly, in the builder you just provide an API key or service account credential. For the samples, we are using the Application default credentials because it's simpler and more secure configuration.

    Reacted by Frank Natividad
  8. frankyn commented on Jun 19, 2017

    @frankyn
    frankyn
    on Jun 19, 2017
    Contributor
    More actions

    Thanks @gguuss! @redserpent7 let us know if this worked for you.

  9. redserpent7 commented on Jun 20, 2017

    @redserpent7
    redserpent7
    on Jun 20, 2017
    Author
    More actions

    @frankyn Perfect thank you so much. And I hope you update the documentation to show that

  10. frankyn
    closed this as completedon Jun 20, 2017
  11. frankyn commented on Jun 20, 2017

    @frankyn
    frankyn
    on Jun 20, 2017
    Contributor
    More actions

    Great! Let us know if anything else comes up! We will update the documentation with this information soon.

  12. frankyn commented on Jun 20, 2017

    @frankyn
    frankyn
    on Jun 20, 2017
    Contributor
    More actions

    I posted this answer to your stackoverflow question as well.

  13. Solido commented on Jun 27, 2017

    @Solido
    Solido
    on Jun 27, 2017
    More actions

    Using Gax:grpc 0.21.1 I got .setCredentialsProvider marked as deprecated and my json auth that is working well when loaded with GoogleCredentials on gcloud storage throws
    The Application Default Credentials are not available using the previous snippet with Speech Api.
    Asking for GOOGLE_APPLICATION_CREDENTIALS and ignoring the conf.

    Reacted by Swapnil Sawant, Daniel Zurek and Houssainatou
  14. Charles92011 commented on Oct 9, 2017

    @Charles92011
    Charles92011
    on Oct 9, 2017
    More actions

    @frankyn I'm trying your solution, but it doesn't work for me.
    SpeechSettings.defaultChannelProviderBuilder is undefined
    SpeechSettings.defaultBuilder is deprecated
    and SpeechSettings.defaultBuilder,setChannelProvider is undefined.

    Your solution is only a couple of months old, I can't image it's out of date.

  15. Charles92011 commented on Oct 9, 2017

    @Charles92011
    Charles92011
    on Oct 9, 2017
    More actions

    @Solido I gleaned this from a comment inside of SpeechClient.Java, it works for me:

    		FileInputStream credentialsStream = new FileInputStream(fileName);
    		GoogleCredentials credentials = GoogleCredentials.fromStream(credentialsStream);
    		FixedCredentialsProvider credentialsProvider = FixedCredentialsProvider.create(credentials);
    
    		SpeechSettings speechSettings = 
    				SpeechSettings.newBuilder()
    					.setCredentialsProvider(credentialsProvider)
    					.build();		
    
    		SpeechClient speech = SpeechClient.create(speechSettings);		
    
    
    Reacted by Saquibul Islam Waheed, Ernesto Perez, Jimi Wang, Kevin Piazzoli Felix Perez, Avanika Gabani, tamirmich, hua21best, Robert Felker, Samuel Humeau, Vasil Vasilev and 4 more
    Reacted by Jonathan and Avanika Gabani
    Reacted by Hasitha Jayawardana
  16. ihunzai-dev commented on Feb 2, 2018

    @ihunzai-dev
    ihunzai-dev
    on Feb 2, 2018
    More actions

    export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json is not working @frankyn

    I have already set env variable using the command, but client library is still throwing same Exception

    OS: Ubuntu 16.0 Server

  17. hua21best commented on Jul 23, 2019

    @hua21best
    hua21best
    on Jul 23, 2019
    More actions

    @redserpent7 @Charles92011 thanks,Very useful to me

  18. averikitsch
    added a commit that references this issue on Oct 27, 2022

    docs(sample): clean up README for native image sample (#697)

    d9510f0
  19. minherz
    added 3 commits that reference this issue on Nov 9, 2022

    chore: release 0.122.7-SNAPSHOT (#697)

    e3e059e

    chore: release 0.122.7-SNAPSHOT (#697)

    694bd7d

    chore: release 0.122.7-SNAPSHOT (#697)

    4e7949b
  20. charlieyu1996
    added 2 commits that reference this issue on Nov 10, 2022

    chore(deps): update dependency com.google.cloud:libraries-bom to v24.…

    afc51f4

    chore(deps): update dependency com.google.cloud.samples:shared-config…

    a10e12e
  21. Sita04
    added 2 commits that reference this issue on Nov 11, 2022

    deps: update dependency org.seleniumhq.selenium:selenium-java to v4.1…

    b8f472a

    deps: update dependency org.seleniumhq.selenium:selenium-java to v4.1…

    0adcee2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @frankyn
    frankyn

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.