Android Google Geolocation API возвращает ошибку 403

я пытаюсь создать приложение для Android, которое может получить местоположение пользователя из Google Geolocation Api. Я конфигурирую и настраиваю платежный аккаунт

Мои настройки

  1. Увеличить квоту до 100/запрос/пользователь
  2. Настройка платежного аккаунта
  3. Разрешенный ip: любой

я использую класс асинхронной задачи

   // 1. create HttpClient
                HttpClient httpclient = new DefaultHttpClient();

                // 2. make POST request to the given URL
                HttpPost httpPost = new HttpPost("https://www.googleapis.com/geolocation/v1/geolocate?key=API_KEY");

                String json = "";

                // 3. build jsonObject
                JSONObject jsonObject = new JSONObject();
                jsonObject.accumulate("homeMobileCountryCode", 310);
                jsonObject.accumulate("homeMobileNetworkCode", 410);
                jsonObject.accumulate("radioType", "gsm");
                jsonObject.accumulate("carrier", "vodafone");

                JSONArray cellTowersArray = new JSONArray();;
                JSONObject cellTowerObject = new JSONObject();;
                cellTowerObject.accumulate("cellId", 42);
                cellTowerObject.accumulate("locationAreaCode", 415);
                cellTowerObject.accumulate("mobileCountryCode", 310);
                cellTowerObject.accumulate("mobileNetworkCode", 410);
                cellTowerObject.accumulate("age", 0);
                cellTowerObject.accumulate("signalStrength", -60);
                cellTowerObject.accumulate("timingAdvance", 15);
                cellTowersArray.put(cellTowerObject);
                jsonObject.accumulate("cellTowers", cellTowersArray);

                JSONArray wifiAccessPointsArray = new JSONArray();
                JSONObject wifiAccessPointObject = new JSONObject();
                wifiAccessPointObject.accumulate("macAddress", "01:23:45:67:89:AB");
                wifiAccessPointObject.accumulate("age", 0);
                wifiAccessPointObject.accumulate("channel", 11);
                wifiAccessPointObject.accumulate("signalToNoiseRatio", 40);
                wifiAccessPointsArray.put(wifiAccessPointObject);
                jsonObject.accumulate("wifiAccessPoints", wifiAccessPointsArray);

                // 4. convert JSONObject to JSON to String
                json = jsonObject.toString();


                // 5. set json to StringEntity
                StringEntity se = new StringEntity(json);;

                // 6. set httpPost Entity
                httpPost.setEntity(se);

                // 7. Set some headers to inform server about the type of the content
                httpPost.setHeader("Accept", "application/json");
                httpPost.setHeader("Content-type", "application/json");

                // 8. Execute POST request to the given URL
                HttpResponse httpResponse = httpclient.execute(httpPost);

                // 9. receive response as inputStream
                inputStream = httpResponse.getEntity().getContent();

                // 10. convert inputstream to string
                if(inputStream != null)
                    result = convertInputStreamToString(inputStream);
                else
                    result = "Did not work";
            }
            catch (MalformedURLException e) {
            	 Log.e("YOUR_APP_LOG_TAG1", "", e);
            }
            catch (IOException e) {
            	 Log.e("YOUR_APP_LOG_TAG2", "", e);
            }
            catch (Exception e) {
            	 Log.e("YOUR_APP_LOG_TAG3", "", e);;
            }

            return result;
        }

        @Override
        protected void onPostExecute(String result) {
            Log.d("result", result);
            
        }
    

    private static String convertInputStreamToString(InputStream inputStream) throws IOException{
          BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));;
          String line = "";
          String result = "";
          while((line = bufferedReader.readLine()) != null)
              result += line;

          inputStream.close();
          return result;
    }   
	

но я все еще получаю сообщение об ошибке 403, разрешенный IP-адрес не является конфигурацией

Помощь/Предложение приветствуются. Спасибо


person Rahul kumar    schedule 29.05.2015    source источник


Ответы (1)


Я считаю это нашим Сам. если у вас возникли проблемы с использованием API геолокации Google и ошибка 403. то вы должны выполнить следующие шаги. это просто :)

  1. уменьшить количество запросов API до 0
  2. затем отключите API геолокации
  3. Создать новый проект
  4. Затем включите Google Geolocation API.
  5. Добавить/увеличить No запроса API
  6. Создайте ключ API Android
  7. API-ключ сервера
  8. Используй это

и все готово, теперь вы можете с легкостью использовать API геолокации Google.

Надеюсь поможет спасибо

person Rahul kumar    schedule 10.06.2015