Calling Google Places/Nearby API from inside an iOS App - ios

I'm trying to call the Google Places API to return a list of restaurants near me. When I call this from a browser it works fine. However, when I call this from inside an iOS App I built using Ionic Framework, it fails with a data NULL, status 0 error.
I researched quite a bit, figured out this was a CORS issue. I looked up Google documentation on how to issue GET requests for iOS App. I used my app's bundle id to create a key and client ID for my app. Using the steps here https://developers.google.com/accounts/docs/OAuth2InstalledApp#overview, I obtained an access_token, which I used as a query parameter just like the docs mentioned. Nothing works. What is going wrong?
URL that works on browser: https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=MyServerApplicationsKey&location=33.85463,-84.35870&rankby=distance&types=restaurant
URL that fails from IOS App: https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=MyiOSApplicationsKey&location=33.85463,-84.35870&rankby=distance&types=restaurant&access_token=MyToken
#plexer
I use the server key to call the URL from the browser. That works, as mentioned. From the App if I use this key, I get the following error:
{"data":null,"status":0,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"sameUrlThatWorksOnBrowser","headers":{"Accept":"application/json, text/plain, /"}},"statusText":""}

The Google Places API uses a Public API Access key, rather than oAuth. The good news is that these are a lot simpler to get started with.
Follow the instructions under the Authentication section on this page to create a new Public API access key, then include that key in the &key parameter for your application.
After clicking the "Create new Key" button, select "Server key". That's a bit weird, since you are calling the API from iOS, but it will work.

Related

iOS GoogleMap API key, If keep it as blank will be generated any issue?

I have just simple question. I'm using goole map and direction API. So I need to create API key thats fine, I have done it.
But When I edit my API key and select Application restrictions to iOS Apps and save it.
I'm using this key in my app then I'm getting below error message.
This IP, site or mobile application is not authorized to use this API key. Request received from IP address XXX.XXX.XX.XXX, with empty referer
But If I remove the application bundle id from iOS Apps then API key is working
Also I'm referring this question This IP, site or mobile application is not authorized to use this API key
But some confusion are, Can we keep it as blank? There is any security related issue? do I need to do any changes when I'm going to upload app on app store ?
NOTE: I'm using API key in all the places in the coding. like
GMSServices.provideAPIKey(googleAPIKey)
and
let urlString = "https://maps.googleapis.com/maps/api/directions/json?origin=\(myCoordinateStr)&destination=\(destinationCoorinateStr)&key=\(googleAPIKey)&sensor=true"

Request Denied in Google Maps geocode API iOS

I am trying to integrate google maps in my iOS App. I created and tried the iOS key, Server key and browser key as well. I regenerated the keys, but still gets the status as "ACCESS DENIED". I have seen many answers here, but none of the solutions work for me. I get the following response
This API project is not authorized to use this API. Please ensure that this API is activated in the APIs Console
and sometimes this
"error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address xxx.xxx.xxx.xxx, with empty referer"
And I tried to use the regenerated key, and i get the following result.
"error_message" : "The provided API key is expired."
The solution may be simple, but I'm really stuck. Any help is appreciated
the log or error is clear.
for use google_maps you must :
• register your app bundle in Google Developer
• get api key ( if you had get it before update it)
• call the google initialize in AppDelegate
[GMSServices provideAPIKey:GOOGLE_MAP_SERVICE];

This IP, site or mobile application is not authorized to use this API key. How to fix this issue for an ios app?

I'm working on Augmented reality in ios app. I found a nice tutorial and a sample project from this site. While running that app in my device, I received the error in NSLOG console,
Response: {
"error_message" = "This IP, site or mobile application is not authorized to use this API key.";
"html_attributions" = (
);
results = (
);
status = "REQUEST_DENIED";
}
I'd created a new project in Google dev site and created Sever Key as iOS Key is not supported for Google places Api. I'd also tried with browser key, it didn't work.
My Request url is look like below,
<NSMutableURLRequest https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=12.974760,80.225061&radius=1000&key=AIzaXXXXXXXXXXXXXXXXXXXMQ&sensor=true>
Tried some solutions suggested here in SO, but no luck. Any suggestions will be appreciated.
The issue is with generating browser keys. while generating new browser key, we should not enter any website urls in the websites tab, instead of that directly clicking generate button could give a new browser key.
While using that key, the issue got fixed.
Choose browser key only without any website name then it will work for android,
I tried for both server key and android key but it is not working for me.

ios flickr api: Flickr callback URL not being called

I'm attempting to hook my application into Flickr but having issues during the Authentication process.
I've followed instructions in:
https://github.com/devedup/FlickrKit
I've created a CFBundleURLTypes for my application (let's call it myapp://) and tested that it works (i.e. I type myapp:// in a safari). I've successfully called the authentication URL in Flickr, it shows the login, asks the user to grant my app the necessary permissions then instead of redirecting back to my app via my URL...it does nothing, and the app is not authenticated.
I used FlickrKit demo app replacing its api key/secret/CFbundleUrltypes with mines and the issue is the same, so the problem is not in the code but rather in the way i registered my app in flickr. Said that...I just followed the instructions in Flickr "Edit Authentication Flow" so I guess the issue is with the callback url I put in flickr. I used myapp://auth? as described in many posts in the internet but does not authenticate or call back my app.
This is not the same issue reported here:
Flickr Authentication Flow and iPhone
but rather similar to the unanswered post:
flickr callback URL not working
The Info.plist for the custom URL handler and the AppDelegate code are a copy&paste from the flickrKit demo app [no need to reinvent the wheel] and anyway even after changing api key secret and url in flickrKit demo app with mines...the app is not called back, so it must be something wrong in my app registration.
Anybody experienced a similar behavior ? i ruled out objective-c code and callback url as the issue, so what is left is the flickr part but not sure where to look for help... so i wrote this post.
Thanks for any tip,
dom
Probably this is a problem of api signature calculation. All the parameters passed via method should be used to calculate an api signature.

Google API fails to authenticate when iOS client ID is used

I'm trying to integrate the Google Data API into my application. I'm using the ObjC wrapper available here:
http://code.google.com/p/gdata-objectivec-client
but I have got some issues with the authentication. Basically I'm following the steps as described here:
http://code.google.com/p/gtm-oauth2/wiki/Introduction#Signing_In_to_Google_Services
I have created a project on the API Console and added two client IDs for installed applications: one is of the "Other" platform, the other is "iOS" with the bundle ID appropriately set (though I left the appstore id 0 for the moment). Now comes the interesting part.
Both the YouTubeSample app bundled with the above wrapper library AND my iOS app work perfectly with the client ID belonging to the "Other" platform, and both of them return a 400 invalid_client error when I switch the ID for the iOS one. I have doublechecked the client IDs and secrets, all are correct. The iOS app has of course been given the correct bundle ID.
So, am I missing something trivial here?
Is there a reason that you need to use the iOS-type id/secret pair instead of the other-type pair? Perhaps I'm missing something, but the linked documentation states to not use an iOS type client id:
In the console, create a project, then click "API Access" in the left column. Create a new Client ID for an Installed Application (not a web application) type other (not iOS). This will provide Client ID and Secret strings to be used with the controller.
The controller likely doesn't identify itself as an iOS application when sending the requests, which Google probably checks when it receives an iOS id/secret pair.

Resources