如何通过api(.net)从AdWords检索广告系列的展示位置

时间:2015-09-11 11:30:01

标签: c# .net api google-adwords

如何通过api(.net)从AdWords检索广告系列的展示位置? 我见过这个piece of code,但我不能通过c#做类似的事情。

此外,我尝试通过报告PLACEMENT_PERFORMANCE_REPORT获取链接,但我不能。

  public static string GetReport(AdWordsUser user, string customerId)
    {



        string postData = string.Format("__rdxml={0}", System.Web.HttpUtility.UrlEncode(@"<reportDefinition xmlns=""https://adwords.google.com/api/adwords/cm/v201506"">
          <selector>
            <fields>CampaignId</fields>
            <fields>Impressions</fields>
            <fields>Clicks</fields>
            <fields>Cost</fields>
            <fields>FinalUrls</fields>
            <predicates>
              <field>Impressions</field>
              <operator>GREATER_THAN</operator>
              <values>0</values>
            </predicates>
          </selector>
          <reportName>Custom Campaign Performance Report</reportName>
          <reportType>PLACEMENT_PERFORMANCE_REPORT</reportType>
          <dateRangeType>ALL_TIME</dateRangeType>
          <downloadFormat>XML</downloadFormat>
        </reportDefinition>"));

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://adwords.google.com/api/adwords/reportdownload/v201506");
        request.Headers.Add("Authorization", "Bearer " + user.OAuthProvider.AccessToken);
        request.Headers.Add("developerToken", "MyToken");
        request.Headers.Add("clientCustomerId", customerId);
        request.Headers.Add("skipReportSummary", "true");
        request.Headers.Add("skipReportHeader", "true");
        request.Method = "POST";

        byte[] byteArray = Encoding.UTF8.GetBytes(postData);

        request.ContentType = "application/x-www-form-urlencoded";

        var requestWriter = request.GetRequestStream();
        requestWriter.Write(byteArray, 0, byteArray.Length);
        requestWriter.Close();
        string responseData = "";
        try
        {
            StreamReader responseReader = new StreamReader(request.GetResponse().GetResponseStream());
            responseData = responseReader.ReadToEnd();
            responseReader.Close();
            request.GetResponse().Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            return "";
        }




        return responseData;
    }

0 个答案:

没有答案