func (tapi *TwitterAPI) get_statuses(id string, p ...*oauth.Pair) ([]byte, error) { var params oauth.Params for _, x := range p { if x != nil { params.Add(x) } } resp, geterr := tapi.authcon.Get("https://api.twitter.com/1.1/statuses/"+id+".json", params, tapi.access_token) if geterr != nil { return nil, geterr } tapi.UpdateRatelimit(resp.Header) return ioutil.ReadAll(resp.Body) }
func (s *YQLStmt) Query(args []driver.Value) (driver.Rows, error) { if err := s.bind(args); err != nil { return nil, err } var res *http.Response var err error if len(s.c.key) > 1 { // secure yqlOauth := &oauth.OAuthConsumer{ Service: "yql", RequestTokenURL: "https://api.login.yahoo.com/oauth/v2/get_request_token", AccessTokenURL: "https://api.login.yahoo.com/oauth/v2/get_token", CallBackURL: "oob", ConsumerKey: s.c.key, ConsumerSecret: s.c.secret, Timeout: 5e9, } p := oauth.Params{} p.Add(&oauth.Pair{Key: "format", Value: "json"}) p.Add(&oauth.Pair{Key: "q", Value: s.q}) res, err = yqlOauth.Get(endpoint, p, nil) if err != nil { return nil, err } } else { url := fmt.Sprintf("%s?q=%s&env=store://datatables.org/alltableswithkeys&format=json", endpoint, url.QueryEscape(s.q)) fmt.Println("url is: ", url) res, err = http.Get(url) } if err != nil { return nil, err } defer res.Body.Close() var data interface{} err = json.NewDecoder(res.Body).Decode(&data) if err != nil { fmt.Println("error is:", err) return nil, errors.New("Invalid Json: %v") } fmt.Println("data is", data) if data == nil { fmt.Println("data nil") return nil, errors.New("Unsupported result") } var ok bool data = data.(map[string]interface{})["query"] if data == nil { fmt.Println("query nil") return nil, errors.New("Unsupported result") } data = data.(map[string]interface{})["results"] if data == nil { fmt.Println("results nil") return nil, errors.New("Unsupported result") } results, ok := data.(map[string]interface{}) if !ok { fmt.Println("data not ok") return nil, errors.New("Unsupported result") } fmt.Println("results-------->", results) for _, v := range results { if vv, ok := v.([]interface{}); ok { fmt.Println("vv ok------->", v) return &YQLRows{s, 0, vv}, nil } } fmt.Println("unknown error") return nil, errors.New("May be a single row response") //return nil, nil }
func (s *YQLStmt) Query(args []driver.Value) (driver.Rows, error) { if err := s.bind(args); err != nil { return nil, err } var res *http.Response var err error if len(s.c.key) > 1 { // secure yqlOauth := &oauth.OAuthConsumer{ Service: "yql", RequestTokenURL: "https://api.login.yahoo.com/oauth/v2/get_request_token", AccessTokenURL: "https://api.login.yahoo.com/oauth/v2/get_token", CallBackURL: "oob", ConsumerKey: s.c.key, ConsumerSecret: s.c.secret, Type: oauth.TWOLEGGED, Timeout: 5e9, } //log.Println("getting oauth? ", s.q) //log.Println(yqlOauth) p := oauth.Params{} p.Add(&oauth.Pair{Key: "format", Value: "json"}) p.Add(&oauth.Pair{Key: "q", Value: s.q}) res, err = yqlOauth.Get(YQL_URL, p, nil) if err != nil { log.Println(err) return nil, err } } else { url := fmt.Sprintf("?q=%s&format=json", YQL_URL, url.QueryEscape(s.q)) //log.Println(url) res, err = http.Get(url) } if err != nil { return nil, err } defer res.Body.Close() var data interface{} b, err := ioutil.ReadAll(res.Body) //log.Println(string(b)) err = json.Unmarshal(b, &data) if err != nil { return nil, errors.New(fmt.Sprintf("Invalid Json: %v", err)) } if data == nil { return nil, errors.New("Unsupported result") } var ok bool data = data.(map[string]interface{})["query"] if data == nil { return nil, errors.New("Unsupported result") } data = data.(map[string]interface{})["results"] if data == nil { return nil, errors.New("Unsupported result") } results, ok := data.(map[string]interface{}) if !ok { return nil, errors.New("Unsupported result") } for _, v := range results { if vv, ok := v.([]interface{}); ok { return &YQLRows{s, 0, vv}, nil } } return nil, errors.New("Unsupported result") }
func (s *YQLStmt) Query(args []driver.Value) (driver.Rows, error) { if err := s.bind(args); err != nil { return nil, err } var res *http.Response var err error if len(s.c.key) > 1 { // secure yqlOauth := &oauth.OAuthConsumer{ Service: "yql", RequestTokenURL: "https://api.login.yahoo.com/oauth/v2/get_request_token", AccessTokenURL: "https://api.login.yahoo.com/oauth/v2/get_token", CallBackURL: "oob", ConsumerKey: s.c.key, ConsumerSecret: s.c.secret, Timeout: 5e9, } p := oauth.Params{} p.Add(&oauth.Pair{Key: "format", Value: "json"}) p.Add(&oauth.Pair{Key: "q", Value: s.q}) s, rt, err := yqlOauth.GetRequestAuthorizationURL() if err != nil { return nil, err } var pin string fmt.Printf("Open %s In your browser.\n Allow access and then enter the PIN number\n", s) fmt.Printf("PIN Number: ") fmt.Scanln(&pin) at := yqlOauth.GetAccessToken(rt.Token, pin) res, err = yqlOauth.Get(endpoint, p, at) if err != nil { return nil, err } } else { values := url.Values{} values.Add("q", s.q) values.Add("format", "json") if s.c.env != "" { values.Add("env", s.c.env) } url := endpoint + "?" + values.Encode() res, err = http.Get(url) } if err != nil { return nil, err } defer res.Body.Close() var data interface{} err = json.NewDecoder(res.Body).Decode(&data) if err != nil { return nil, errors.New(fmt.Sprintf("Invalid Json: %v", err)) } if data == nil { return nil, errors.New("Unsupported result") } var ok bool data = data.(map[string]interface{})["query"] if data == nil { return nil, errors.New("Unsupported result") } data = data.(map[string]interface{})["results"] if data == nil { return nil, errors.New("Unsupported result") } results, ok := data.(map[string]interface{}) if !ok { return nil, errors.New("Unsupported result") } var last interface{} for _, v := range results { if vv, ok := v.([]interface{}); ok { return &YQLRows{s, 0, vv}, nil } last = v } if last != nil { return &YQLRows{s, 0, []interface{}{last}}, nil } return nil, errors.New("Unsupported result") }
func googleSearch(ctx *web.Context, name string) { if googleAT == nil { ctx.WriteString("<h1>Google Search</h1>") ctx.WriteString("<p>Please <a href=\"/signin/google\">Sign in to Google</a></p>") return } googleGetSearch(ctx, name) q := GetParam(ctx, "q") lat := GetParam(ctx, "lat") lon := GetParam(ctx, "lon") radius := GetParam(ctx, "radius") // Defaults params := oauth.Params{ &oauth.Pair{Key: "q", Value: q}, &oauth.Pair{Key: "key", Value: "Change to your app API KEY"}, &oauth.Pair{Key: "alt", Value: "json"}, } //q=query&lat=latitude&lon=longitude&radius=radius if lat != "" && lon != "" && radius != "" { params.Add(&oauth.Pair{Key: "lat", Value: lat}) params.Add(&oauth.Pair{Key: "lon", Value: lon}) params.Add(&oauth.Pair{Key: "radius", Value: radius}) } r, err := googleConn.Get( "https://www.googleapis.com/buzz/v1/activities/search", params, googleAT) b, _ := ioutil.ReadAll(r.Body) var m map[string]gobuzz.ActivityFeed err = json.Unmarshal(b, &m) if err != nil { ctx.WriteString(err.String()) return } feed := m["data"] ctx.WriteString("<h2>" + feed.Title + "</h2>") for i := range feed.Items { activity := feed.Items[i] t := (time.Time)(activity.Published) c := t.Format("1 January 2006 @ 3:04 pm") ctx.WriteString("<div>") ctx.WriteString("<h2>" + activity.Title + "</h2>") ctx.WriteString("<div>" + activity.Object.Content + "<p>Published : " + c + "</p></div>") ctx.WriteString("</div>") } }