Я пытаюсь найти изображения с помощью Google Custom Search api.Android и Google Custom Search API
Каждый раз, когда я получаю ошибку 403. Что я делаю неправильно?
Я зарегистрировал проект в консоли разработчика Google, включил API пользовательского поиска и создал Key для приложений для Android.
У меня есть апи ключ и ого идентификатор
Код для получения результатов поиска:
String key = "AIzaSyBixxZ28popSAyP0YdlzvnWFECXktLQR4w";
String cx = "009034774129468977321:wl08kmocg3m";
String qry = "spring";// search key word
try {
HttpRequestInitializer httpRequestInitializer = new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
}
};
JsonFactory jsonFactory = new JacksonFactory();
HttpTransport httpTransport = new NetHttpTransport();
Customsearch customsearch = new Customsearch.Builder(httpTransport, jsonFactory, httpRequestInitializer)
.setApplicationName("CTTProject")
.build();
Customsearch.Cse.List list = customsearch.cse().list(qry);
list.setKey(key);
list.setCx(cx);
Search results = list.execute();
List<Result> items = results.getItems();
for (Result item : items) {
Log.d("Response", item.toString());
}
} catch (IOException e) {
e.printStackTrace();
}
каждый раз, когда я получаю результат:
886-895/gsihome.reyst.ctt W/System.err﹕ com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
886-895/gsihome.reyst.ctt W/System.err﹕ {
886-895/gsihome.reyst.ctt W/System.err﹕ "code" : 403,
886-895/gsihome.reyst.ctt W/System.err﹕ "errors" : [ {
886-895/gsihome.reyst.ctt W/System.err﹕ "domain" : "usageLimits",
886-895/gsihome.reyst.ctt W/System.err﹕ "message" : "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.",
886-895/gsihome.reyst.ctt W/System.err﹕ "reason" : "accessNotConfigured",
886-895/gsihome.reyst.ctt W/System.err﹕ "extendedHelp" : "https://console.developers.google.com"
886-895/gsihome.reyst.ctt W/System.err﹕ } ],
886-895/gsihome.reyst.ctt W/System.err﹕ "message" : "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration."
886-895/gsihome.reyst.ctt W/System.err﹕ }
У меня есть та же проблема, но не exacly. Mine one: «В вашем API-интерфейсе настроено ограничение для каждого IP-адреса или каждого рефератора, и запрос не соответствует этим ограничениям. Используйте Google Developers Console, чтобы обновить конфигурацию ключа API, если запрос от этого IP-адреса или реферера должен быть позволил.". В большинстве случаев вы не включили пользовательский API поиска. Вы должны перейти на console.developers.google.com, откройте свой проект. Перейдите к «API» и включите переключатель «Custom Search API». –