0

我正在开发一些 C# 项目以对Adwords进行 API 调用以下载数据。

我已经通过以下方式获得了访问令牌:

WebRequest webRequest = HttpWebRequest.Create("https://www.google.com/accounts/ClientLogin");
        webRequest.Method = "POST";
        webRequest.ContentType = "application/x-www-form-urlencoded";

        string postParams =

            "accountType=" + HttpUtility.UrlEncode("GOOGLE") +
            "&Email=" + HttpUtility.UrlEncode("xxxx@xxxx.com") +
            "&Passwd=" + HttpUtility.UrlEncode("xxxx") +
            "&service=" + HttpUtility.UrlEncode("adwords") +
            "&source=" + HttpUtility.UrlEncode(string.Format("{0}-{1}-{2}", "sample1",
                "sample2", "1"));

        byte[] postBytes = Encoding.UTF8.GetBytes(postParams);
        webRequest.ContentLength = postBytes.Length;

        using (Stream strmReq = webRequest.GetRequestStream())
        {
            strmReq.Write(postBytes, 0, postBytes.Length);
        }

        string retVal = "";
        try
        {
            WebResponse response = webRequest.GetResponse();

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                string sResponse = reader.ReadToEnd();
                string[] splits = sResponse.Split('\n');
                foreach (string split in splits)
                {
                    string[] subsplits = split.Split('=');
                    if (subsplits.Length >= 2 && subsplits[0] == "Auth")
                    {
                        retVal = subsplits[1];
                    }
                }
            }
        }
        catch (WebException ex)
        {
            throw new ApplicationException("Could not generate auth token.", ex);
        }

如果有人可以让我知道进行 API 调用以下载数据的下一步是什么,我将不胜感激。https://developers.google.com/adwords/api/docs/guides/reporting

谢谢。

4

1 回答 1

0

除了@Jon 提到的关于使用客户端库的内容之外,您还应该查看下载的示例目录,特别是报告示例,以及报告定义的 XML 模式,以根据您的特定要求修改示例。

于 2012-12-07T03:39:41.693 回答