回复评论API | Google Play Developer API

时间:2016-06-09 18:24:49

标签: android api google-play google-play-services google-play-developer-api

我正在为我的公司创建一个网络/应用程序(在我的空闲时间),为我们的客户提供访问权限,以便检索和回复我们为他们发布的应用程序的Google评论。 谷歌发布了一个Reply to Reviews API,它应该适用于此。

我无法找出Gaining Access部分。

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

我知道在示例中它使用的是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();
    }
}
}

2 个答案:

答案 0 :(得分:0)

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

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

所以有两种方法。

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

    编辑/resources/client_secrets.json文件并添加客户端ID,   客户端秘密和重定向uris。使用它执行任何示例类   main()方法开始auth流程:

         

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

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

这是Github中的完整示例。

答案 1 :(得分:0)

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