I am trying to build an application for internal business use that will
pull Adwords Custom Reports automatically.
I've attained a developer's token, and an access code which I refresh every
hour. I've also written a code in VB.Net (translated from C# code) to make
a request and get a response. However I get an error every time I try to
get a response from my request. Below is the VB Code, and below that is the
XML in TextBox1.Text for the report I want to attain.
(I've commented on where the error occurs)
VB Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim reportdefinitionxml As String = TextBox1.Text
Dim accesstoken As String = "XXXXXXXXX"
Dim clientcustomerid As String = "XXX-XXX-XXXX"
Dim developertoken As String = "XXXXXXXXXX"
Dim filepath As String =
My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\adwordsapi.txt"
Dim version As String = "v201506"
Dim downloadurl As Uri = New
Uri("https://adwords.google.com/api/adwords/reportdownload/" & version)
Dim request As WebRequest = HttpWebRequest.Create(downloadurl)
request.Headers.Add("clientCustomerId: " & clientcustomerid)
request.Headers.Add("developerToken: " & developertoken)
request.Headers.Add("Authorization: Bearer " & accesstoken)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
Using writer As System.IO.StreamWriter = New
System.IO.StreamWriter(request.GetRequestStream)
writer.Write("__rdxml=" &
System.Web.HttpUtility.UrlEncode(reportdefinitionxml))
End Using
Dim response As WebResponse = Nothing
Dim success As Boolean = False
Try
response = request.GetResponse 'This is where an error occurs'
success = True
Catch ex As WebException 'The error exception is {"The remote
server returned an error: (400) Bad Request."}'
response = ex.Response
End Try
DownloadReportToFile(filePath, response)
End Sub
XML in Textbox1.Text:
<reportDefinition xmlns="https://adwords.google.com/api/adwords/cm/v201506">
<selector>
<fields>CampaignId</fields>
<fields>Id</fields>
<fields>Impressions</fields>
<fields>Clicks</fields>
<fields>Cost</fields>
<predicates>
<field>Status</field>
<operator>IN</operator>
<values>ENABLED</values>
<values>PAUSED</values>
</predicates>
</selector>
<reportName>Custom Adgroup Performance Report</reportName>
<reportType>ADGROUP_PERFORMANCE_REPORT</reportType>
<dateRangeType>LAST_7_DAYS</dateRangeType>
<downloadFormat>CSV</downloadFormat>
</reportDefinition>
If anybody could point out where I am going wrong that would be most
appreciated.
Thanks!
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at http://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/d2ff3f22-e367-440b-b4bc-d6da8fe36c51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.