【问题标题】:Reply to Reviews API | Google Play Developer API回复评论 API | Google Play 开发者 API
【发布时间】:2016-06-09 18:24:49
【问题描述】:

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

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

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

我知道在示例中它使用的是 Plus 服务。 我的问题是,我应该使用什么服务?我假设 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();
    }
}
}

【问题讨论】:

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


    【解决方案1】:

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

    要使用回复评论 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。使用其 main() 方法执行任何示例类 在你的 IDE 脚本会输出一个 apk 列表。

    这是Github 中的完整示例。

    【讨论】:

    • 很抱歉,我应该提到我正在尝试在 C# 中执行此操作。你知道用 C# 来完成这个任务吗?
    • 所以我得到了在 Java 中运行的 Github 示例。在回复评论 API 文档中,它说要检索一组评论:“使用 GET 方法请求您的应用程序的评论列表。在您的请求中,包括您的应用程序的完全限定包名称 - 例如 com. google.android.apps.maps——以及您在访问 API 时收到的授权令牌。” GET https://www.googleapis.com/androidpublisher/v2/applications/your_package_name/reviews? access_token=your_auth_token 什么是授权令牌? @noogui
    • @MichaelRuby 您必须按照一些步骤获取授权令牌。在此处查看详细信息:stackoverflow.com/a/67294595/6907424
    【解决方案2】:

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

    【讨论】:

    • 答案的必要部分应该在这里。
    猜你喜欢
    • 2013-06-17
    • 2022-11-13
    • 1970-01-01
    • 2017-09-12
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多