OAuth的谷歌趋势下载CSV文件 [英] Oauth google trends download CSV file

查看:425
本文介绍了OAuth的谷歌趋势下载CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图构建一个使用过的数据的谷歌趋势和/或谷歌的洞察力一个Web应用程序,但我已经遇到了一点路块。谷歌趋势只允许你下载的CSV文件,如果您登录在一个有效的谷歌帐户。因此,我不能让我的web应用程序下载,并分析它们。

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.

这使我开始寻找到的OAuth HTTP://$c$c.google.com/apis/accounts /docs/OAuth.html ,但我有点不知所措。

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

尝试使用谷歌趋势的URL与 HTTP://google$c$csamples.com/oauth_playground/ 生成无效的范围错误的谷歌趋势的URL。

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

我不能使用OAuth来访问这些服务?我已经做了一堆的搜索,但没有发现任何真正可靠的例子(至少那些我能理解)如何正确地使用它。有没有更好的方式来做到这一点?

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?

任何人都帮我出去呢?

推荐答案

截至2013年4月30日这工作。请注意,你打他们的配额pretty的快速执行此操作的方法。

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

        }
    }

这篇关于OAuth的谷歌趋势下载CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆