1

I'm trying to work with Google My Business API. I was able to successfully setup the OAuth 2.0 Playground to work and some simple C# code using the Google.Apis.MyBusinessAccountManagement.v1 library. Now that I have those 2 things working I'm trying to move on to my goal which is get a list of reviews for my business. For the C# library, the MyBusinessAccountManagementService object doesn't have any methods for reviews. So I researched a bunch and found an API call to a different endpoint https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews and decided to try with the Oauth2.0 Playground using both the https://www.googleapis.com/auth/business.manage and https://www.googleapis.com/auth/plus.business.manage scopes; but for some reason on this endpoint I get the PERMISSION_DENIED error (see below). I already went over the process to fill out the form to get my project associated with the Business and the API is set as Enabled (see image)

{
  "error": {
    "status": "PERMISSION_DENIED", 
    "message": "Google My Business API has not been used in project {projectId} before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/mybusiness.googleapis.com/overview?project={projectId} then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.", 
    "code": 403, 
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.Help", 
        "links": [
          {
            "url": "https://console.developers.google.com/apis/api/mybusiness.googleapis.com/overview?project={projectId}", 
            "description": "Google developers console API activation"
          }
        ]
      }, 
      {
        "reason": "SERVICE_DISABLED", 
        "@type": "type.googleapis.com/google.rpc.ErrorInfo", 
        "domain": "googleapis.com", 
        "metadata": {
          "consumer": "projects/{projectId}", 
          "service": "mybusiness.googleapis.com"
        }
      }
    ]
  }
}

My Business API Enabled

All APIs Enabled

Leonardo Tanoue
  • 181
  • 1
  • 4
  • 13
  • Does this answer help? https://stackoverflow.com/a/71489050 – vpgcloud Dec 02 '22 at 21:45
  • please edit your question and include [example] i would like to test your issue with the .net client library. – Linda Lawton - DaImTo Dec 03 '22 at 10:57
  • @vpriesner unfortunately that answer doesn't help. I have the Private API enabled on my project already. I added a second picture with all enabled API's for my project – Leonardo Tanoue Dec 05 '22 at 13:21
  • @DaImTo The .Net client library is missing the API request I need. That's why I'm stuck on this process now. I'm trying to figure out the API request using REST instead of the client library. The OAuth2 Playground is tool to help with testing REST calls to the Google API. – Leonardo Tanoue Dec 05 '22 at 13:23
  • most of that api was depreciated have you checked which endpoints are working? – Linda Lawton - DaImTo Dec 05 '22 at 14:08
  • @DaImTo I don't care about other endpoints besides the one I'm trying to use which is the review one. As far as I can tell based on the documentation that one is not deprecated: https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews – Leonardo Tanoue Dec 05 '22 at 15:22

2 Answers2

2

I found out what I was doing wrong. In the OAuth 2.0 Playground, there's a settings button where you need to enter your application's Client ID and Secret; I did that the first time forgot every time after that; so I was using some default Application for testing instead of my own. After adding those two I kept working and found out that I had the wrong location ID. The correct way to get your location ID is once you are a manager of a Business Location you need to go to the Location Manager page on Google and find the Business Profile ID under Advanced Settings. Don't use the Google Maps tool to get the location ID for Google Maps those are different IDs!

enter image description here


EDIT 01/19/2023

I was able to get the Google API to work with my request in C# code!

using Google.Apis.Auth.OAuth2;
using Google.Apis.MyBusinessAccountManagement.v1;
using Google.Apis.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

HttpClient client = new HttpClient();

using IHost host = Host.CreateDefaultBuilder(args).Build();
var configuration = new ConfigurationBuilder().AddJsonFile($"appsettings.json", optional: false, reloadOnChange: true);
var config = configuration.Build();

Console.WriteLine($"Hello, World! You are in the {config.GetValue<string>("General:Environment")} Environment");

UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.FromStream(stream).Secrets,
        new[] { "https://www.googleapis.com/auth/business.manage" },
        "user", CancellationToken.None);
}

var service = new MyBusinessAccountManagementService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "{ProjectName}",
    ApiKey = "{API Key}"
});

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "https://mybusiness.googleapis.com/v4/accounts/{accountid}/locations/{locationid}/reviews");
var response = await service.HttpClient.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();
Console.WriteLine(json);

// API call to get Accounts
// var accounts = await service.Accounts.List().ExecuteAsync();
//Console.WriteLine(accounts.ToString());

Console.ReadLine();

await host.RunAsync();
Leonardo Tanoue
  • 181
  • 1
  • 4
  • 13
0

Oauth2 play ground is only used for testing, its not meant for antyhing more then that.

Google My Business API has not been used in project {projectId} before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/mybusiness.googleapis.com/overview?project={projectId} then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

Means exactly the api has not ben enabled in that project yet. You need to go under library and enable it.

There are about 7 different apis listed in google cloud console related to My Business API . May I suggest you enable them all until you find the one you are missing.

As for the .net client library remember alot of the My Business API's were deprecated they may not work anymore, have you checked the documentation.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • That's correct, the Oauth2 Playground is used for testing, it's a great learning tool before you have to code anything. It's been really helpful so far. I'm editing the question to add another pictures with all API's I have enabled which are all Business API's available. There are plenty of documentation that says the reviews API has not been deprecated, here are some examples: https://developers.google.com/my-business/content/review-data and https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews – Leonardo Tanoue Dec 05 '22 at 13:25