1
我試圖訪問谷歌使用代碼這樣的地方API從AppEngine上:嘗試訪問使用谷歌API客戶端谷歌地方GAE
字符串PLACES_DETAILS_URL =「https://maps.googleapis.com/maps/api /地點/信息/ JSON「;
// setup up the HTTP transport
HttpTransport transport = new UrlFetchTransport();
// add default headers
GoogleHeaders defaultHeaders = new GoogleHeaders();
transport.defaultHeaders = defaultHeaders;
transport.defaultHeaders.put("Content-Type", "application/json");
JsonHttpParser parser = new JsonHttpParser();
parser.jsonFactory = new JacksonFactory();
transport.addParser(parser);
// build the HTTP GET request and URL
HttpRequest request = transport.buildGetRequest();
request.setUrl(PLACES_DETAILS_URL);
GenericData data = new GenericData();
data.put("reference", restaurantGoogleId);
data.put("sensor", "false");
data.put("key", ApplicationConstants.GoogleApiKey);
JsonHttpContent content = new JsonHttpContent();
content.jsonFactory=new JacksonFactory();
content.data = data;
request.content = content;
try {
HttpResponse response = request.execute();
String r = response.parseAsString();
r=r;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
即使這是推薦的方式,我也不知道。如果是這樣,爲什麼這不起作用?如果我直接在瀏覽器中發送請求,它會起作用,但使用此代碼時,它總是會返回「拒絕請求」。
在此先感謝。
u能告訴庫需要此代碼工作? – Vik 2012-06-12 00:14:43