Last active
October 10, 2016 21:18
-
-
Save NaotoKumagai/7d247b4d8fe86f41d9d0363130786b0e to your computer and use it in GitHub Desktop.
GoogleCustomSearchを適当に叩く(エラーガン無視...)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/franela/goreq" | |
) | |
type Parameter struct { | |
Key string | |
Q string | |
Cx string | |
Num uint8 | |
SearchType string `url:"searchType"` //全て小文字に変換されてしまうので、明示的にキー名を指定 | |
} | |
func main() { | |
url := "https://www.googleapis.com/customsearch/v1/" | |
param := Parameter { | |
Key: "【APIキー】", | |
Cx: "【検索エンジンID】", | |
Q: "google", // 検索ワード | |
SearchType: "image", // 今回は画像検索 | |
Num: 3, // 検索結果の数 | |
} | |
fmt.Printf(search(url,param)) | |
} | |
func search(url string,query interface{}) (string) { | |
res, _ := goreq.Request{ | |
Uri: url, | |
QueryString: query, | |
ShowDebug: true, | |
}.Do() | |
str, _ := res.Body.ToString() | |
return str | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment