我已经成功完成了我的项目,并在我的本地主机上进行了很多测试,一切似乎工作正常,但问题出现在我将它加载到我们的远程服务器上时。当我第一次将它加载到服务器上时,没有数据被拉,我收到谷歌的消息,有人试图破坏我的帐户,当我检查出它是服务器的IP地址。所以我进入了我的分析帐户,并授予了对该帐户的服务器访问权限,并使用了那里提供的api密钥,但它仍然没有提取任何数据。
请帮助我这里是我的代码
using System;
using System.Collections.Specialized;
using System.Data.SqlClient;
using System.IO;
using System.Net;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Globalization;
using System.Xml;
using DotNetOpenAuth.OAuth2;
using DotNetOpenAuth.Messaging;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis;
using log4net;
using System.Security.Cryptography.X509Certificates;
using Google.GData.Analytics;
using Google.GData.Client;
using Google.GData.Client.ResumableUpload;
public partial class Summary : System.Web.UI.Page
{
string username, pass, gkey;
public void MainOC()
{
username = "nnnnnnnn@gmail.com";
pass = "xxxxxxxxxxx";
gkey = "?key=nnnnnnnnnnnnnnnnnnnn";
DataFeed();
}
public void DataFeed()
{
string dataFeedUrl = "https://www.google.com/analytics/feeds/data" + gkey;
string accountFeedUrl = "https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties" + gkey;
AnalyticsService service = new AnalyticsService("API Project");
service.setUserCredentials(username, pass);
DataQuery query1 = new DataQuery(dataFeedUrl);
DataQuery query = new DataQuery(accountFeedUrl);
query1.Ids = "ga:" + lblView_ID.Text;
query1.Dimensions = lblResultDimension.Text;
query1.Metrics = lblResultMetrics.Text;
query1.Sort = "ga:visits";
query1.GAStartDate = new DateTime(2012, 1, 2).ToString(txtStartDate.Text);
query1.GAEndDate = DateTime.Now.ToString(txtEndDate.Text);
query1.StartIndex = 1;
query1.NumberToRetrieve = 50;
DataFeed dataFeedVisits = service.Query(query1);
DataFeed aF = service.Query(query);
for (int i = 0; i < cblCustomerList.Items.Count; i++)
{
if (cblCustomerList.Items[i].Selected == true)
{
TableHeaderRow hrow = new TableHeaderRow();
TableHeaderCell hcell = new TableHeaderCell();
hcell.Text += cblCustomerList.Items[i].Text.ToString();
hrow.Cells.Add(hcell);
tblAnalytics.Rows.Add(hrow);
//lblTitles.Text += cblCustomerList.Items[i].Text.ToString() + "</br>";
}
}
tblValue.Rows.Clear();
foreach (DataEntry entry in dataFeedVisits.Entries)
{
string st = entry.Title.Text;
string visits = entry.Metrics[0].Value;
TableRow vrow = new TableRow();
TableCell vcell = new TableCell();
vcell.Text += st + visits;
vrow.Cells.Add(vcell);
tblValue.Rows.Add(vrow);
}
}
}
提前致谢。