需要使用C#和Reports API

时间:2016-12-18 18:49:00

标签: c# google-api google-admin-sdk google-api-dotnet-client google-reporting-api

我在C#上使用.NET客户端库来为特定目的构建一个小型应用程序。

我需要返回'gmail_used_quota_in_mb'和'total_quota_in_mb'的值以及'used_quota_in_mb'

基于此页面(https://developers.google.com/admin-sdk/reports/v1/reference/usage-ref-appendix-a/users-accounts)我应该在我的应用程序请求的输出中获取参数,但是我没有得到这些值......

我正在使用以下代码执行此操作:

string nl = Environment.NewLine;
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets,
        new[] { ReportsService.Scope.AdminReportsUsageReadonly },
        "user", CancellationToken.None, new FileDataStore("Reports.ListSizes"));
}

// Create the service.
var service = new ReportsService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "Reports API Sample",
});

try
{
    UserUsageReportResource.GetRequest request = service.UserUsageReport.Get("x@y.z", "2016-12-16");
    IList<UsageReport> result = request.Execute().UsageReportsValue;
    foreach (var item in result)
    {
        AppendTextBox(textBox1.Text + "User ID=" + item.Parameters[0].StringValue);
        // In the Parameters[] array, I get 46 items, none of them is one of the above 3 parameters I am looking for...
    }           
}
catch(Google.GoogleApiException ex)
{
    MessageBox.Show(ex.Message, "Error");
}

在Parameters []数组中,我得到46个项目,其中没有一项是我正在寻找的上述3个参数之一......

我从下一页获取了大部分代码,并根据UsageReport的需要对其进行了调整: https://developers.google.com/admin-sdk/reports/v1/quickstart/dotnet

我非常感谢任何帮助,主要是我是一名系统工程师,我正在开发一个G Suite迁移项目,需要让这个应用程序能够完成数据迁移的关键部分。

编辑(额外细节):以下是我从输出中得到的所有参数......

  

帐户:admin_set_name = XXXXX   账户:is_disabled =   账户:disabled_reason =   帐户:如first_name = XXXXX   账户:is_2sv_enforced =   账户:is_2sv_enrolled =   账户:is_delegated_admin =   账户:is_less_secure_apps_access_allowed =   账户:is_super_admin =   账户:is_suspended =   帐户:姓氏= XXXXX   账户:num_authorized_apps =   账户:num_roles_assigned =   账户:num_security_keys =   帐户:CREATION_TIME =   账户:last_login_time =   账户:last_sso_time =   账户:user_has_overridden_​​name =   文档:num_owned_google_documents_created =   文档:num_owned_google_documents_edited =   文档:num_owned_google_documents_trashed =   文档:num_owned_google_documents_viewed =   文档:num_owned_google_drawings_created =   文档:num_owned_google_drawings_edited =   文档:num_owned_google_drawings_trashed =   文档:num_owned_google_drawings_viewed =   文档:num_owned_google_forms_created =   文档:num_owned_google_forms_edited =   文档:num_owned_google_forms_trashed =   文档:num_owned_google_forms_viewed =   文档:num_owned_google_presentations_created =   文档:num_owned_google_presentations_edited =   文档:num_owned_google_presentations_trashed =   文档:num_owned_google_presentations_viewed =   文档:num_owned_google_spreadsheets_created =   文档:num_owned_google_spreadsheets_edited =   文档:num_owned_google_spreadsheets_trashed =   文档:num_owned_google_spreadsheets_viewed =   文档:num_owned_items_created =   文档:num_owned_items_edited =   文档:num_owned_items_trashed =   文档:num_owned_items_viewed =   文档:num_owned_other_types_created =   文档:num_owned_other_types_edited =   文档:num_owned_other_types_trashed =   文档:num_owned_other_types_viewed =

由于

1 个答案:

答案 0 :(得分:1)

好的,如果用户在检索报告时没有数据,则以下值不会出现在报告中:

  • drive_used_quota_in_mb
  • gmail_used_quota_in_mb
  • gplus_photos_used_quota_in_mb
  • total_quota_in_mb
  • used_quota_in_mb
  • used_quota_in_percentage

我想这对我来说是一个足够的验证方法,如果用户有数据显示值,那么我可以比较数据大小。如果用户没有数据,则不会返回这些值,因此我假设他的数据使用率为0。

我花了一段时间才发现,因为我运行报告的用户实际上有数据,但由于报告数据的机制可用,我正在搜索用户没有数据的时间。当我输入'all'搜索参数时,我在某些帐户中获得了那些在搜索日期之前有数据的值,这让我更加困惑。

但今天能够安静地坐下来检查每一个案子后,我得出了这个结论。我只希望Google在参数输出页面上更多地指出...