0
こんにちはみんな、イムは、この2つの機能でGoogleカスタム検索を行っている:エキスは、Googleカスタム検索の結果
Thread thread = new Thread(new Runnable()
{
@Override
public void run()
{
try {
// looking for
String strNoSpaces = str.replace(" ", "+");
// Your API key
String key="AIzaSyBewkknFVuG68bIjao5sg98kYuPmZuNLvs";
// Your Search Engine ID
String cx = "013787635589838199944:m7q-rztdo1w";
String url2 = "https://www.googleapis.com/customsearch/v1?q=" + strNoSpaces + "&key=" + key + "&cx=" + cx + "&alt=json";
Log.d("search", "Url = "+ url2);
String result2 = httpGet(url2);
result.setText(result2);
}
catch(Exception e) {
System.out.println("Error1 " + e.getMessage());
}
}
public String httpGet(String urlStr) throws IOException, JSONException {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if(conn.getResponseCode() != 200) {
throw new IOException(conn.getResponseMessage());
}
Log.d("search", "Connection status = " + conn.getResponseMessage());
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while((line = rd.readLine()) != null) {
Log.d("search", "Line =" + rd.readLine());
sb.append(line+"\n");
}
rd.close();
conn.disconnect();
return sb.toString();
}
そして、これは私が例を探し、TextViewの中で見た結果である「カラオケ」 :私が欲しいもの
はTextViewの中で各ビデオの唯一のタイトルとリンクを参照することです。この場合、 "King King Karaoke"とその次の曲を検索しますが、どうしたらよいか考えていません:)とてもありがとうございます。