0

I am working on creating a web/app for my company (in my free time) to provide access for our customers to retrieve and reply to google reviews for apps we have published for them. Google has released a Reply to Reviews API which should work for this.

I haven't been able to figure out the Gaining Access portion.

I'm trying to use a service account. I've created an OAuth2 service account, granted access, downloaded a private key, and tired to follow the sample provided here (below).

I know that in the example it is using a Plus service. My questions are, what service am I supposed to be using? I'm assuming the plus service is not what I want.

Is generating a certificate this way the correct way to get the auth_token (in the Reply to Reviews API documentation)?

Thanks for your help!

using System;
using System.Security.Cryptography.X509Certificates;

using Google.Apis.Auth.OAuth2;
using Google.Apis.Plus.v1;
using Google.Apis.Plus.v1.Data;
using Google.Apis.Services;

namespace Google.Apis.Samples.PlusServiceAccount
{
/// <summary>
/// This sample demonstrates the simplest use case for a Service Account service.
/// The certificate needs to be downloaded from the Google Developers Console
/// <see cref="https://console.developers.google.com/">
///   "Create another client ID..." -> "Service Account" -> Download the certificate,
///   rename it as "key.p12" and add it to the project. Don't forget to change the Build action
///   to "Content" and the Copy to Output Directory to "Copy if newer".
/// </summary>
public class Program
{
    // A known public activity.
    private static String ACTIVITY_ID = "z12gtjhq3qn2xxl2o224exwiqruvtda0i";

    public static void Main(string[] args)
    {
        Console.WriteLine("Plus API - Service Account");
        Console.WriteLine("==========================");

        String serviceAccountEmail = "SERVICE_ACCOUNT_EMAIL_HERE";

        var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);

        ServiceAccountCredential credential = new ServiceAccountCredential(
           new ServiceAccountCredential.Initializer(serviceAccountEmail)
           {
               Scopes = new[] { PlusService.Scope.PlusMe }
           }.FromCertificate(certificate));

        // Create the service.
        var service = new PlusService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "Plus API Sample",
        });

        Activity activity = service.Activities.Get(ACTIVITY_ID).Execute();
        Console.WriteLine("  Activity: " + activity.Object.Content);
        Console.WriteLine("  Video: " + activity.Object.Attachments[0].Url);

        Console.WriteLine("Press any key to continue...");
        Console.ReadKey();
    }
}
}

2 Answers2

0

My questions are, what service am I supposed to be using? I'm assuming the plus service is not what I want.

To work with the Reply to Reviews API, you provide authorization using either an OAuth client or a service account.

So there are two ways.

  1. Using OAuth2: Installed application

Edit the /resources/client_secrets.json file and add the client ID, client secret and redirect uris. Execute any sample class using its main() method to begin the auth flow:

A browser window will open and ask you to login. Make sure the account has appropriate permissions in the Google Play Developer console. Accept the permissions dialog. The browser should display The authentication flow has completed. Close the window and go back into your IDE and check the console output. The script will output a list of apks. The tokens will be stored in .store/android_publisher_api in your home folder. Remove this file to restart the auth flow.

  1. using OAuth2: Service accounts Edit ApplicationConfig.java and add the service account email address. Copy the service account key file, generated in the Google APIs Console into the same directory and rename it to key.p12. Execute any sample class using its main() method in your IDE The script will output a list of apks.

Here's a full sample in Github.

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
  • I'm sorry I should have mentioned that I am trying to do this in C#. Do you know of a way to accomplish this using C#? – Michael Ruby Jun 10 '16 at 15:57
  • 1
    So I've got the Github example working in Java. In the Reply to Reviews API documentation it says to retrieve a set of reviews: "Use the GET method to request a list of reviews for your app. In your request, include the fully-qualified package name for your app—such as com.google.android.apps.maps—and the authorization token you received when gaining access to the API." `GET https://www.googleapis.com/androidpublisher/v2/applications/your_package_name/reviews? access_token=your_auth_token` **What is the authorization token?** @noogui – Michael Ruby Jun 14 '16 at 20:19
  • @MichaelRuby you have to get the authorization token following some steps. See details here: https://stackoverflow.com/a/67294595/6907424 – hafiz031 Apr 28 '21 at 06:38
0

You need to use Google Android Publisher API for access to reviews and reply to them. https://developers.google.com/android-publisher/reply-to-reviews#retrieving_reviews