Created
December 30, 2014 15:44
-
-
Save shibayan/117a2ef85a8b5a4ae2d5 to your computer and use it in GitHub Desktop.
今年書いた記事で読まれていないトップ 10 を出す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Security.Cryptography.X509Certificates; | |
using Google.Apis.Analytics.v3; | |
using Google.Apis.Auth.OAuth2; | |
using Google.Apis.Services; | |
namespace ConsoleApplication5 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var certificate = new X509Certificate2(Convert.FromBase64String(ServiceAccountCertificate), "notasecret", X509KeyStorageFlags.Exportable); | |
var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer("********") | |
{ | |
Scopes = new[] { AnalyticsService.Scope.Analytics, AnalyticsService.Scope.AnalyticsReadonly } | |
}.FromCertificate(certificate)); | |
var service = new AnalyticsService(new BaseClientService.Initializer | |
{ | |
HttpClientInitializer = credential, | |
ApplicationName = "sample", | |
}); | |
var resource = service.Data.Ga.Get("ga:********", "2014-01-01", "2014-12-31", "ga:pageviews"); | |
resource.Dimensions = "ga:pagePath"; | |
resource.Filters = "ga:pagePath=~^/entry/2014[0-9]{4}/[0-9]{10}$"; | |
resource.Sort = "ga:pageviews"; | |
resource.MaxResults = 10; | |
var data = resource.Execute(); | |
foreach (var row in data.Rows) | |
{ | |
Console.WriteLine(string.Join(",", row)); | |
} | |
} | |
private const string ServiceAccountCertificate = "********"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment