0
我有一個函數可以檢索Google Directions,但我有一個關於在哪裏可以找到Google Crypto Key來簽署我的URL的問題。儀表板上的這個在哪裏?如何簽署URL Google路線?
public static void getDirections(Context context, String origin, String destination,
final DirectionsListener listener)
throws ExecutionException, InterruptedException {
if (FrameworkUtils.isStringEmpty(origin) || FrameworkUtils.isStringEmpty(destination)) {
return;
}
try {
String url = String.format(GOOGLE_API_DIRECTIONS_URL, origin, destination,
ConfigurationManager.GOOGLE_CLIENT_KEY, KEY_TRAVEL_MODE_DRIVING);
String signedUrl = UrlSigner.signURL(url);
JsonRequest request = new JsonRequest(Method.GET, signedUrl, null, new JsonResponseListener() {
@Override
public void onResponse(JSONObject response, int resultCode) {
try {
JSONArray routesObject = response.getJSONArray(KEY_ROUTES);
JSONObject currentRoute = routesObject.getJSONObject(0);
JSONObject overViewPolyline = currentRoute.getJSONObject(KEY_OVERVIEW_POLYLINE);
String encodedPoints = overViewPolyline.getString(KEY_POINTS);
listener.onSuccess(decode(encodedPoints));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onResponse(JSONObject jsonObject) {
// do nothing
}
}, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
// do nothing
}
@Override
public void onErrorResponse(VolleyError error, int resultCode) {
// do nothing
}
}, 45);
VolleyClient.getInstance(context.getApplicationContext()).addRequest(request);
} catch (IOException | InvalidKeyException | NoSuchAlgorithmException | URISyntaxException e) {
e.printStackTrace();
}
}
這裏是我的signURL功能
public static String signURL(String inputUrl) throws IOException, InvalidKeyException, NoSuchAlgorithmException, URISyntaxException {
URL url = new URL(inputUrl);
String googleCryptoKey = ConfigurationManager.GOOGLE_CRYPTO_KEY;
UrlSigner signer = new UrlSigner(googleCryptoKey);
String request = signer.signRequest(url.getPath(), url.getQuery());
return url.getProtocol() + "://" + url.getHost() + request;
}
我創建從例子的代碼,但我摸不清的谷歌加密密鑰應該是什麼?
儀表板具有
- API密鑰創建
- 從AIM &聯繫我可以看到一個項目ID和項目編號
有人能幫助這一點?