C# - 获取PlayStore中的所有应用评论

时间:2017-06-06 19:40:55

标签: c# google-analytics proxy google-api google-play

我想创建一个解决方案来获取PlayStore中的所有应用评论,但我不知道该怎么做。我有一个用于连接Google Analytics的代码,但在运行时我遇到了很多错误。

以下是代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Google.Apis.AnalyticsReporting.v4;
using Google.Apis.AnalyticsReporting.v4.Data;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;

namespace Google_api
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                var filepath = "...";  // path to the json file for the Service account
                var viewid = "..."; // ID to access your view in G.A

                GoogleCredential credentials;

                using (var stream = new FileStream(filepath, FileMode.Open, FileAccess.Read))
                {
                    string[] scopes = { AnalyticsReportingService.Scope.AnalyticsReadonly };
                    var googleCredential = GoogleCredential.FromStream(stream);
                    credentials = googleCredential.CreateScoped(scopes);
                }

                var reportingService = new AnalyticsReportingService(
                    new BaseClientService.Initializer
                    {
                        HttpClientInitializer = credentials
                    });

                var dateRange = new DateRange
                {
                    StartDate = "2017-05-01",
                    EndDate = "2017-05-31"
                };

                var sessions = new Metric
                {
                    Expression = "ga:sessions",
                    Alias = "Sessions"
                };

                var date = new Dimension { Name = "ga:date" };

                var reportRequest = new ReportRequest
                {
                    DateRanges = new List<DateRange> { dateRange },
                    Dimensions = new List<Dimension> { date },
                    Metrics = new List<Metric> { sessions },
                    ViewId = viewid
                };

                var getReportsRequest = new GetReportsRequest
                {
                    ReportRequests = new List<ReportRequest> { reportRequest }
                };

                var batchRequest = reportingService.Reports.BatchGet(getReportsRequest);
                var response = batchRequest.Execute();
                foreach (var x in response.Reports.First().Data.Rows)
                {
                    Console.WriteLine(string.Join(", ", x.Dimensions) + "   " + string.Join(", ", x.Metrics.First().Values));
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.ReadLine();
        }
    }
}

我收到了这个错误:

  

System.Configuration.ConfigurationErrorsException:创建&#39; system.net/defaultproxy'中指定的Web代理时出错;   ---&GT; System.Net.Sockets.SocketException:提供的参数无效   System.Net.SafeCloseSocketAndEvent.CreateWSASocketWithEvent(AddressFamily   addressFamily,SocketType socketType,ProtocolType protocolType,   布尔值autoReset,布尔符号信号)   System.Net.NetworkAddressChangePolled..ctor()in   System.Net.AutoWebProxyScriptEngine.AutoDetector.Initialize()in   System.Net.AutoWebProxyScriptEngine.AutoDetector.get_CurrentAutoDetector()   在System.Net.AutoWebProxyScriptEngine..ctor中(WebProxy代理,布尔值   在System.Net.WebProxy.UnsafeUpdateFromRegistry()中的useRegistry)   System.Net.WebProxy..ctor(Boolean enableAutoproxy)in   System.Net.Configuration.DefaultProxySectionInternal..ctor(DefaultProxySection   部分)   System.Net.Configuration.DefaultProxySectionInternal.GetSection() -   ---内部异常堆栈跟踪结束---       在Google.Apis.Requests.ClientServiceRequest&#39; 1.Execute()       在Google_api.Program.Main(String [] args)na X:\ example \ Program.cs:line 64

我将创建一个指标,以便使用GA捕获PlayStore中的所有评论。这可能吗?如果没有,你能帮帮我吗?我想要了解PlayStore中的所有评论以及评价我的应用的设备的所有信息。评论API仅返回有关评论的信息。如果有人可以提供一些示例代码或指出我正确的方向使用.net API获取一些基本的报告数据,那将非常感激。

谢谢! (抱歉我的英语不好......)

0 个答案:

没有答案