【问题标题】:Retrieve information from google search console using Search Console APIs in C#使用 C# 中的 Search Console API 从谷歌搜索控制台检索信息
【发布时间】:2019-10-02 14:30:22
【问题描述】:

我能够成功地从 Google Analytics Reporting API 检索详细信息,但是当我尝试使用 C# 中的 Search Console API 从 Google Search Console 访问网站(属性)详细信息时,它不会检索任何信息。基本上我需要获取网站列表(用户的 Search Console 网站)和每个关键字的访问者。 我正在使用Google Webmaster Tool APIs Search Console API v3。在 APIs Expolorer 中,它检索站点列表(webmasters.sites.list)。当我尝试在 C# 控制台应用程序中实现相同的方法时,它不会获取任何数据。请检查下面的代码和附图。

 GoogleCredential credentials;
        using (var stream = new FileStream(filepath, FileMode.Open, FileAccess.Read))
        {
            string[] scopes = {
                //AnalyticsService.Scope.Analytics, // view and manage your Google Analytics data
                //AnalyticsService.Scope.AnalyticsEdit, // Edit and manage Google Analytics Account
                //AnalyticsService.Scope.AnalyticsManageUsers, // Edit and manage Google Analytics Users
                //AnalyticsReportingService.Scope.AnalyticsReadonly,
                 //AnalyticsReportingService.Scope.Analytics,
                WebmastersService.Scope.WebmastersReadonly,
                WebmastersService.Scope.Webmasters
           };

            var googleCredential = GoogleCredential.FromStream(stream);
            credentials = googleCredential.CreateScoped(scopes);

        }

 WebmastersService service1 = new WebmastersService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credentials
        });

        SitesResource.ListRequest res = service1.Sites.List();
        var sites = res.Execute();

【问题讨论】:

    标签: c# .net visual-studio google-analytics google-search-console


    【解决方案1】:

    我终于通过将具有完全权限的谷歌“服务帐户”添加到选定属性的谷歌搜索控制台来解决这个问题。步骤如下。

    1. 在 google 中使用管理员帐户登录

    2. 转到搜索控制台网站 (https://search.google.com/u/0/search-console)

    3. 选择左上角的属性“https://www.----.com
    4. 左侧菜单中的“设置”
    5. “用户和权利”
    6. 右上角“添加用户”
    7. 添加了我们的谷歌“SERVICE 帐户”并拥有完整权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多