使用.NET的Google Adwords API获取每月对特定关键字的搜索次数 [英] Get number of monthly searches for specific keywords using Google Adwords API for .NET

查看:114
本文介绍了使用.NET的Google Adwords API获取每月对特定关键字的搜索次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助,如何获取给定关键字的每月搜索量.

I need help how to get number of monthly searches for given keywords.

我有Google Adwords API帐户,而且已经加载了钱,因此我可以提出许多请求.但是我无法从示例中找到代码,以及如何获取此信息.

I got Google Adwords API account and also money is loaded so i can make many requests. But i can't find the code from examples, how to get this info.

我正在使用C#.NET,并且已经下载了Google.AdWords API dll.

I'm using C# .NET, and have downloaded Google.AdWords API dll's.

能给我一个简单的例子吗?

Can you give me some simple example?

推荐答案

也许有一种更为优美的方式来获取关键字,但是我发现我需要一个临时报告.我无法将其与AdWords .Net客户端库配合使用,但是以老式的方式构建HTTP请求并不是一件繁琐的事情.

There may be a more graceful way to get keywords, but I found that I needed an ad hoc report. I could not get this to work with the AdWords .Net Client Library, but building an HTTP request the old-fashioned way is not a huge chore.

这是我用于创建请求标头的代码:

This is my code for creating the request header:

var  request = (HttpWebRequest)WebRequest.Create(Properties.Settings.Default.AdHocReportsURL);
request.ContentType = "application/x-www-form-urlencoded";
request.Method      = "POST";
request.Headers.Add("Authorization: GoogleLogin auth=" + _authToken);
request.Headers.Add("clientCustomerId: " + _customerID.ToString("000-000-0000"));
request.Headers.Add("developerToken: "   + _developerToken);

然后,您需要为临时报告附加XML规范.这是我的方法:

You then need to append the XML spec for your ad hoc report. Here's my method:

private void  AppendReportSpec(HttpWebRequest request, ReportType reportType, IEnumerable<string> fields, DateTime startDate, DateTime endDate)
    {
    var  reportSpec = new StringBuilder("<reportDefinition><selector>");
    foreach (string field in fields)
        {
        reportSpec.Append("\t\t<fields>");
        reportSpec.Append(field);
        reportSpec.AppendLine("</fields>");
        }
    reportSpec.Append
        (
        @"<dateRange><min>{0}</min><max>{1}</max></dateRange>
        </selector>
        <reportName>Whatever</reportName>
        <reportType>{2}</reportType>
        <dateRangeType>CUSTOM_DATE</dateRangeType>
        <downloadFormat>CSV</downloadFormat>
        </reportDefinition>"
        );

    string  reportXml = String.Format(reportSpec.ToString(), startDate.ToString("yyyyMMdd"), endDate.ToString("yyyyMMdd"), reportType);

    using (var requestContent = new StreamWriter(request.GetRequestStream()))
        requestContent.Write("__rdxml=" + HttpUtility.UrlEncode(reportXml));
    }

最后,您可以解析request.GetResponse()中的值以获取数据.

Finally, you can parse the value in request.GetResponse() to get your data.

请参见 http://code.google.com /apis/adwords/docs/appendix/reports.html#search-query 获取报告类型列表(您可能需要KEYWORDS_PERFORMANCE_REPORT)以及每种类型中允许使用的字段.

See http://code.google.com/apis/adwords/docs/appendix/reports.html#search-query for the list of report types (you'll probably want KEYWORDS_PERFORMANCE_REPORT) and the fields allowed in each.

这篇关于使用.NET的Google Adwords API获取每月对特定关键字的搜索次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆