如果有人需要使用 webrequest 和 clientlogin 从新的分析 api 管理提要中获取他们的表 id。这是我的(快速)代码(感谢 Bengel):
string queryString = String.Format("https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email={0}&Passwd={1}&service=analytics&source={2}", __username, __pass, "yourlog");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(queryString);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string responseContent = new StreamReader(response.GetResponseStream()).ReadToEnd();
string authCode = responseContent.Substring(responseContent.LastIndexOf("Auth=") + 5);
queryString = "https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties/~all/profiles";
request = (HttpWebRequest)WebRequest.Create(queryString);
request.Headers.Add("Authorization", String.Format("GoogleLogin auth={0}", authCode));
response = (HttpWebResponse)request.GetResponse();
XDocument doc = XDocument.Load(new StreamReader(response.GetResponseStream()));
var entries = (from item in doc.Root.Elements("{http://www.w3.org/2005/Atom}entry")
select new
{
tableid = item.Elements("{http://schemas.google.com/analytics/2009}property").ElementAt(4).Attribute("value").Value,
profileid = item.Elements("{http://schemas.google.com/analytics/2009}property").ElementAt(1).Attribute("value").Value
});