Hi All,
I am getting below error while accessing the GA through my C# code
<pre lang="c#">
Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.
Can some one please help me out .
Thanks in advance.
Adding code
Int32 _intVisists = 0;
Int32 _intPageViewVisit = 0;
// your Google analytics username and password here
string userName = "";
string passWord = "";
string gkey = ""; //this is my google analytics aap key
string dataFeedUrl = "https://www.googleapis.com/analytics/v3/data/";
AccountQuery query = new AccountQuery();
AnalyticsService service = new AnalyticsService("Project name");
if (!string.IsNullOrEmpty(userName))
{
service.setUserCredentials(userName, passWord);
}
string str = "ga:123456789";
DataQuery query1 = new DataQuery(dataFeedUrl);
//Data come for FROM date to Date
query1.Ids = str;
query1.Metrics = "ga:socialInteractions";//visitors
query1.Dimensions = "ga:pagePath";
//query1.Sort = "ga:visits";
query1.GAStartDate = "2014-01-27";
query1.GAEndDate = "2014-02-10";
DataFeed dataFeedVisits = service.Query(query1);
foreach (DataEntry entry in dataFeedVisits.Entries)
{
string st = entry.Title.Text;
string ss = entry.Metrics[0].Value;
_intVisists = Int32.Parse(ss);
//Console.WriteLine(ss);
Response.Write("
");
Response.Write("Total Visits : " + ss);
Response.Write("
");
}
// total New visits (count + %)
query1.Ids = str;
query1.Metrics = "ga:newVisits";//visitors
query1.Sort = "ga:newVisits";
query1.GAStartDate = (DateTime.Now).AddDays(-30).ToString("yyyy-MM-dd");
query1.GAEndDate = (DateTime.Now).ToString("yyyy-MM-dd");
query1.StartIndex = 1;
DataFeed dataFeedNwVisits = service.Query(query1);