DataConnector
接続の作成
ADO.NET provider for Google Analytics > 接続の作成

To establish a connection to a Google Analytics data source, the ADO.NET Provider can be used through the C1GoogleAnalyticsConnection class. This class requires a connection string to be provided as an argument, which can be created in either of the following ways:

The following code shows how to use the C1GoogleAnalyticsConnectionStringBuilder class to configure the connection string for Google Analytics, which can then be consumed by the C1GoogleAnalyticsConnection class to establish a connection to Google Analytics server. Through that connection, the data source can be queried.

C#
コードのコピー
static void ReadData()
{
    //C1GoogleAnalyticsConnectionStringBuilder を使用して接続文字列を定義します。            
    C1GoogleAnalyticsConnectionStringBuilder builder = new C1GoogleAnalyticsConnectionStringBuilder();
    builder.KeyFile = KeyFile;
    builder.ViewId = ViewId;

    //コマンドを定義します。
    string sql = "SELECT Source, Sessions FROM Traffic";
    //データを取得します。
    using (var con = new C1GoogleAnalyticsConnection(builder))
    {
        con.Open();
        var command = con.CreateCommand();
        command.CommandText = sql;
        var reader = command.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine(String.Format("{0} --> \t\t{1}", reader["Source"], reader["Sessions"]));
        }
    }
}