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;
}
0 Replies