2Answers
  • 4
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Google Places API + ReactNative

I'm trying to utilize Google Places API in Android app. I'm using React Native and the following package: https://github.com/FaridSafi/react-native-google-places-autocomplete

  1. API key in Google console created
  2. Restriction set to Android app (SHA1 fingerprint + package name)
  3. SHA1 fingerprint and package name values checked with:
    • aapt dump badging app-release.apk
    • unzip -p app-release.apk META-INF/CERT.RSA | keytool -printcert
  4. API key don't have any API usage restriction (can be used with any service)
  5. Places API enabled
  6. Maps JavaScript API enabled
  7. Maps SDK for Android enabled


A) When Android app restriction is set (point 2). I'm getting error:

"google places autocomplete: This IP, site or mobile application is not authorized to use this API key. Request received from IP address xxx.xxx.xxx.xxx, with referrer: undefined"

B) When Android app restriction removed (restriction set to None) everything works fine.

Any ideas?

The Google Places API is designed to be used in server-side applications. There are two other Places SDK for Android / IOS, which is designed to be used with mobile applications. The API restrictions are designed to support only these usage. So using Places API in React native, you are kind of left in a field naked. A proper way to do is to develop a wrapper module to use proper SDK in your react native project. You may want to check https://github.com/tolu360/react-native-google-places.

  • 1
Reply Report
      • 2
    • As the installation document suggested - github.com/FaridSafi/…, You need to use "Google Places API Web Service" (NOT Android or iOS). This API type is there for server-side applications, NOT for mobile phone applications. You need to change your API key restriction to IP Address. However, there is serious drawback here, now your API key is kind of public, and you cannot restrict your API key because it should need to be used by literally ALL IP addresses.

To use this React native project, your Google Place API should be unrestricted. As this is not a Android SDK as well Website with Javascript, so only option left is to unrestirct it.

Better way would be to restrict the API Usage for Places API to avoid misuse.

Please see below screenshot to check How to restrict Google Places API for React Native Autocomplete?

How to restrict Google Places API for React Native Autocomplete

  • 0
Reply Report