0

我正在为我的公司创建一个网络/应用程序(在我的空闲时间),为我们的客户提供访问权限,以检索和回复我们为他们发布的应用程序的谷歌评论。谷歌已经发布了一个回复评论 API应该可以解决这个问题。

我无法弄清楚获得访问权部分。

我正在尝试使用服务帐户。我创建了一个 OAuth2 服务帐户,授予访问权限,下载了私钥,并且厌倦了遵循此处提供的示例(如下)。

我知道在示例中它使用的是 Plus 服务。我的问题是,我应该使用什么服务?我假设加号服务不是我想要的。

以这种方式生成证书是否是获取 auth_token 的正确方法(在回复评论 API 文档中)?

谢谢你的帮助!

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();
    }
}
}
4

2 回答 2

0

您需要使用 Google Android Publisher API 访问评论并回复评论。 https://developers.google.com/android-publisher/reply-to-reviews#retrieving_reviews

于 2016-08-10T14:43:45.103 回答
0

我的问题是,我应该使用什么服务?我假设加号服务不是我想要的。

要使用回复评论 API,您可以使用 OAuth 客户端或服务帐户提供授权。

所以有两种方法。

  1. 使用 OAuth2:已安装的应用程序

编辑 /resources/client_secrets.json 文件并添加客户端 ID、客户端密码和重定向 uri。使用其 main() 方法执行任何示例类以开始身份验证流程:

将打开一个浏览器窗口并要求您登录。确保该帐户在 Google Play 开发者控制台中具有适当的权限。接受权限对话框。浏览器应显示身份验证流程已完成。关闭窗口并返回 IDE 并检查控制台输出。该脚本将输出 apk 列表。令牌将存储在您的主文件夹中的 .store/android_publisher_api 中。删除此文件以重新启动身份验证流程。

  1. 使用 OAuth2:服务帐户编辑 ApplicationConfig.java 并添加服务帐户电子邮件地址。将在 Google API 控制台中生成的服务帐户密钥文件复制到同一目录中,并将其重命名为 key.p12。在 IDE 中使用其 main() 方法执行任何示例类该脚本将输出 apk 列表。

这是Github中的完整示例。

于 2016-06-10T10:57:49.563 回答