【问题标题】:Oauth google trends download CSV file [duplicate]Oauth 谷歌趋势下载 CSV 文件 [重复]
【发布时间】:2011-02-13 20:43:30
【问题描述】:

我正在尝试构建一个使用来自谷歌趋势和/或谷歌洞察力的数据的网络应用程序,但我遇到了一些障碍。如果您使用有效的 Google 帐户登录,Google 趋势仅允许您下载 csv 文件。因此,我无法让我的 Web 应用程序下载并解析它们。

这让我开始研究 OAuth http://code.google.com/apis/accounts/docs/OAuth.html,但我有点不知所措。

尝试使用谷歌趋势网址 http://googlecodesamples.com/oauth_playground/ 为 google 趋势 url 生成无效范围错误。

我可以不使用 Oauth 访问这些服务吗?我做了很多搜索,但没有找到任何关于如何正确使用它的真正可靠的例子(至少是我能理解的例子)。有没有更好的方法来做到这一点?

有人帮我解决这个问题吗?

【问题讨论】:

  • 我知道你曾经能够做到这一点,但它看起来已经被弃用了。

标签: c# .net csv


【解决方案1】:

截至 2013 年 4 月 30 日,此功能有效。请注意,使用此方法您很快就达到了他们的配额。

    static void Main(string[] args)
    {
        using (var client = new WebClient())
        {
            var terms = new List<string>() {"debt", "profit", "euro", "dollar", "financial", "economy", "federal reserve", "earnings", "fed", "consumer spending" , "employment", "unemployment", "jobs" };
            var username = "your username";
            var password = "password";

            var response = client.DownloadString(string.Format("https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email={0}&Passwd={1}&service=trendspro&source=test-test-v1", username, password));

            // The SID is the first line in the response
            // The Auth line
            var auth = response.Split('\n')[2];
            client.Headers.Add("Authorization", "GoogleLogin " + auth);

            int i = 1;
            while (terms.Count > 0)
            {
                // google limits 5 sets of terms per request
                var arr = terms.Take(5).ToArray();
                terms = terms.Skip(5).ToList();

                var joined = string.Join("%2C%20", arr);
                byte[] csv = client.DownloadData(string.Format("http://www.google.com/trends/trendsReport?hl=en-US&q={0}&cmpt=q&content=1&export=1", joined));

                // TODO: do something with the downloaded csv file:
                Console.WriteLine(Encoding.UTF8.GetString(csv));
                File.WriteAllBytes(string.Format("report{0}.csv", i), csv);
                i++;
            }

        }
    }

【讨论】:

    【解决方案2】:

    我正在尝试用不同的编码语言来完成相同的任务。

    在该行中:client.Headers.Add("Authorization", "GoogleLogin" + auth); “+”号是否只是连接两个字符串“GoogleLogin”和“Auth=*****”?

    如果我的实现是正确的,在过去的几个月里授权方法似乎再次发生了变化:(

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多