如何从 java 上的谷歌地图中提取电话号码?

问题描述 投票:0回答:0

` 包 org.example.v1;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;

public class RestaurantScraper {

    private static final String PLACES_API_BASE = "https://maps.googleapis.com/maps/api/place";
    private static final String TYPE_NEARBY_SEARCH = "/nearbysearch";
    private static final String OUT_JSON = "/json";
    private static final String API_KEY = "myKey";
    private static final String LOCATION = "49.842957,24.031111";
    private static final int RADIUS = 5000;
    private static final String TYPE = "restaurant";

   public static void main(String[] args) throws IOException {
    // формуємо запит до Google Maps Places API
    String urlString = PLACES_API_BASE + TYPE_NEARBY_SEARCH + OUT_JSON + "?location=" + LOCATION        
    + "&radius=" + RADIUS + "&type=" + TYPE + "&key=" + API_KEY;
    URL url = new URL(urlString);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("GET");

    // читаємо відповідь від API
    Scanner scanner = new Scanner(conn.getInputStream());
    String response = scanner.useDelimiter("\\A").next();

    // записуємо відповідь у файл
    PrintWriter out = new PrintWriter(new FileWriter("restaurants.csv"));
    out.println(response);
    out.close();
   }
}

`

我想使用 PlacesAPI 从地方提取电话号码,但我不能,我尝试了很多方法,但是当我想使用“formatted_phone_number”提取电话时,这段代码就像被忽略了一样

附言在现场 API_KEY 一切正常,当我运行它时,我把我的钥匙放在那里

java google-places-api
© www.soinside.com 2019 - 2024. All rights reserved.