Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#β€’16mo ago
πŸŒ·πŸ’ morgan πŸŒΊπŸ’

Google Api to C#

Hey I'm trying to connect Places Api to do auto completion on addresses. This is being made on a C# software, I already have the nuget package installed.

The error: Error creating Credential from JSON or JSON parameters

I'm using the downloaded json key from Google console.

The code:
    public override async void _Ready() {
        PlacesClientBuilder placesClient = new PlacesClientBuilder();
        String path = "key.json";
        placesClient.CredentialsPath = path;


        
        // Initialize request argument(s)
        AutocompletePlacesRequest request = new AutocompletePlacesRequest
        {
            Input = "address",
            LocationBias = new AutocompletePlacesRequest.Types.LocationBias(),
            LocationRestriction = new AutocompletePlacesRequest.Types.LocationRestriction(),
            IncludedPrimaryTypes = { "", },
            IncludedRegionCodes = { "", },
            LanguageCode = "",
            RegionCode = "",
            Origin = new Google.Type.LatLng(),
            InputOffset = 0,
            IncludeQueryPredictions = false,
            SessionToken = "",
        };
        // Make the request
        AutocompletePlacesResponse response = placesClient.Build().AutocompletePlaces(request);

        GD.Print(response);
        
    }

    private static UserCredential Login (string googleClientID, string googleClientSecret, string[] scopes) {
        ClientSecrets secrets = new ClientSecrets () {
            ClientId = googleClientID,
            ClientSecret = googleClientSecret
        };

        return GoogleWebAuthorizationBroker.AuthorizeAsync(secrets, scopes, "user", System.Threading.CancellationToken.None).Result;
    }
    public override async void _Ready() {
        PlacesClientBuilder placesClient = new PlacesClientBuilder();
        String path = "key.json";
        placesClient.CredentialsPath = path;


        
        // Initialize request argument(s)
        AutocompletePlacesRequest request = new AutocompletePlacesRequest
        {
            Input = "address",
            LocationBias = new AutocompletePlacesRequest.Types.LocationBias(),
            LocationRestriction = new AutocompletePlacesRequest.Types.LocationRestriction(),
            IncludedPrimaryTypes = { "", },
            IncludedRegionCodes = { "", },
            LanguageCode = "",
            RegionCode = "",
            Origin = new Google.Type.LatLng(),
            InputOffset = 0,
            IncludeQueryPredictions = false,
            SessionToken = "",
        };
        // Make the request
        AutocompletePlacesResponse response = placesClient.Build().AutocompletePlaces(request);

        GD.Print(response);
        
    }

    private static UserCredential Login (string googleClientID, string googleClientSecret, string[] scopes) {
        ClientSecrets secrets = new ClientSecrets () {
            ClientId = googleClientID,
            ClientSecret = googleClientSecret
        };

        return GoogleWebAuthorizationBroker.AuthorizeAsync(secrets, scopes, "user", System.Threading.CancellationToken.None).Result;
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Google Cloud STT API C#
C#CC# / help
4y ago
API connecting C# project to Google Drive
C#CC# / help
3y ago
Google Api help
C#CC# / help
2y ago
❔ Google Api- PermissionDenied
C#CC# / help
3y ago