string grantType = "access_token";
string client_id = "XXXXXX";
string refresh_token = "XXXXXX";
string url = "https://accounts.google.com/o/oauth2/token";
string client_secret = "XXXXXX";
HttpWebResponse response = null;
try
{
// Create the data to send
StringBuilder data = new StringBuilder();
data.Append("&client_id=" + Uri.EscapeDataString(client_id));
data.Append("&client_secret=" + Uri.EscapeDataString(client_secret));
data.Append("&refresh_token=" + Uri.EscapeDataString(refresh_token));
data.Append("grant_type=" + Uri.EscapeDataString(grantType));
// Create a byte array of the data to be sent
byte[] byteArray = Encoding.UTF8.GetBytes(data.ToString());
// Setup the Request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
// Write data
Stream postStream = request.GetRequestStream();
postStream.Write(byteArray, 0, byteArray.Length);
postStream.Close();
// Send Request & Get Response
response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
// Get the Response Stream
string json = reader.ReadLine();
Console.WriteLine(json);
}
}
catch (WebException e)
{
// This exception will be raised if the server didn't return 200 - OK
// Retrieve more information about the error
if (e.Response != null)
{
using (HttpWebResponse err = (HttpWebResponse)e.Response)
{
Console.WriteLine("The server returned '{0}' with the status code '{1}
({2:d})'.",
err.StatusDescription, err.StatusCode, err.StatusCode);
}
}
}
finally
{
if (response != null) { response.Close(); }
}
I get this error on
line response = (HttpWebResponse)request.GetResponse();
I've changed my client id,and so on for "XXXXXX"
I've just get approved developer token and try to download report through
API and always get error
System.Net.WebException: The remote server returned an error: (400) Bad
Request.
at System.Net.HttpWebRequest.GetResponse()
at WindowsFormsApplication1.Form1.DoAuth2Authorization(AdsUser user) in
D:\test\WindowsFormsApplication1\Form1.cs:line 342}
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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].
For more options, visit https://groups.google.com/groups/opt_out.