Oauth 谷歌趋势下载 CSV 文件

发布于 2024-10-17 03:39:07 字数 560 浏览 2 评论 0原文

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

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

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

我可以不使用Oauth来访问这些服务吗?我已经进行了大量搜索,但还没有找到任何真正可靠的示例(至少是我能理解的示例)来说明如何正确使用它。有更好的方法吗?

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

I'm trying to build a web application that uses data off of google trends and/or google insight, but I've run into a bit of a road block. Google Trends only lets you download the csv file if you are logged in on a valid google account. Thus, I can't have my web application download and parse them.

Which lead me to start looking into OAuth
http://code.google.com/apis/accounts/docs/OAuth.html, but I'm a bit overwhelmed.

Trying to use google trends url with
http://googlecodesamples.com/oauth_playground/
generates an invalid scope error for the google trends url.

Can I not use Oauth to access these services? I've done a bunch of searching, but haven't found any really solid examples(at least ones that I can understand) of how to properly use this. Is there a better way to do this?

Anyone help me out on this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡忘如思 2024-10-24 03:39:07

截至 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++;
            }

        }
    }

As of 4/30/2013 this works. Note that you hit their quota pretty fast doing this method.

    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++;
            }

        }
    }
把梦留给海 2024-10-24 03:39:07

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

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

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

I'm trying to achieve the same task in a different coding language.

In the line: client.Headers.Add("Authorization", "GoogleLogin " + auth);
does the "+" sign simply concatenate the two strings "GoogleLogin " and "Auth=*****" ?

Looks like the authorisation method has changed again in the last couple of months if my implementation is correct :(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文