コード例 #1
0
        public static Dictionary <string, object> RefreshToken(string client_id, string client_secret, string refresh_token)
        {
            Dictionary <string, object> dataDict = new Dictionary <string, object>();

            dataDict.Add("client_id", client_id);
            dataDict.Add("client_secret", client_secret);
            dataDict.Add("refresh_token", refresh_token);
            dataDict.Add("grant_type", "refresh_token");
            string res = REST.HttpPost("https://accounts.google.com/o/oauth2/token", dataDict);

            return((Dictionary <string, object>)CountryCodeTopLevelDomain.DecodeJson(res));
        }
コード例 #2
0
        public static string[] GetData2CSV(string url, string access_token)
        {
            string[]      result = new string[2];
            StringBuilder csv    = new StringBuilder();
            Dictionary <string, object> dictJSON = new Dictionary <string, object>();
            string json = REST.HttpGet(url + "&access_token=" + access_token);

            do
            {
                dictJSON = (Dictionary <string, object>)CountryCodeTopLevelDomain.DecodeJson(json);
                if (dictJSON.ContainsKey("error"))
                {
                    result[0] = "FAIL";
                    result[1] = ((Dictionary <string, object>)dictJSON["error"])["message"].ToString();
                    return(result);
                }

                ArrayList headers = (ArrayList)dictJSON["columnHeaders"];
                for (var i = 0; i < headers.Count; i++)
                {
                    var x = (Dictionary <string, object>)headers[i];
                    csv.Append(x["name"].ToString());
                    if (i < headers.Count - 1)
                    {
                        csv.Append(",");
                    }
                }

                csv.AppendLine();

                ArrayList rowData  = (ArrayList)dictJSON["rows"];
                int       rowLines = rowData.Count;
                for (var i = 0; i < rowLines; i++)
                {
                    string    line = string.Empty;
                    ArrayList row  = (ArrayList)rowData[i];
                    for (var j = 0; j < headers.Count; j++)
                    {
                        var s  = string.Empty;
                        var x  = (Dictionary <string, object>)headers[j];
                        var dt = x["dataType"].ToString();
                        if ("STRING" == dt)
                        {
                            s = "\"" + row[j].ToString() + "\"";
                        }
                        else
                        {
                            s = row[j].ToString();
                        }

                        line += s;
                        if (j < headers.Count - 1)
                        {
                            line += ",";
                        }
                    }

                    csv.AppendLine(line);
                }

                if (dictJSON.ContainsKey("nextLink"))
                {
                    json = REST.HttpGet(dictJSON["nextLink"].ToString() + "&access_token=" + access_token);
                }
                else
                {
                    break;
                }
            }while (true);
            result[0] = "OK";
            result[1] = csv.ToString();
            return(result);
        }