google places for iOS empty referrer - ios

I have been working completely fine with google maps sdk and the places api. yesterday my code was running perfectly fine. but woke up this morning, made some modifications then ran into a compiling snowball of issues which seems like an easy fix but have spent a couple hours trying to figure out what is going on. I am trying to develop an iPhone application.
I have gone back, created a "new project" in the developer console
regenerated a new iOS key.
entered the new bundle ID in the info.plist
entered the new api key in the delegate file and within the search parameter of the url.
i am using alamofire and swiftyjson to parse the data
but still get the same issue.
2016-01-28 13:15:55.683 Google Maps SDK for iOS version: 1.11.21919.0
{
"error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address "myIPAddress", with empty referer",
"results" : [
],
"status" : "REQUEST_DENIED",
"html_attributions" : [
]
}
func downloadRestaurantDetails(completed: DownloadComplete) {
let URL_Search = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?"
let API_iOSKey = "My iOS API Key"
let urlString = "\(URL_Search)location=\(clLatitude),\(clLongitude)&radius=\(searchRadius)&types=\(searchType)&key=\(API_iOSKey)"
let url = NSURL(string: urlString)!
Alamofire.request(.GET,url).responseJSON { (response) -> Void in
if let value = response.result.value {
let json = JSON(value)
print(json)
if let results = json["results"].array {
for result in results {
if let placeIDs = result["place_id"].string {
self.placeIDArray.append(placeIDs)
}
}
}
}
completed()
}
}

You've misconfigured your API key.
First, your issue is with the Google Places API Web Service, which can only be used with Server keys not iOS keys. You're calling the web service (https://maps.googleapis.com/maps/place/...) so iOS keys and bundleID key restrictions aren't going to work here (and are likely to confuse things).
So you need to follow the instructions at https://developers.google.com/places/web-service/get-api-key, and make a Server Key with "Google Places API Web Service" enabled in the Developers Console (not the same as "Google Places API for iOS"). To be useful on phones you probably don't want to set any IP restrictions (and IP restrictions are the only kind possible for Server keys). Use that key in your HTTP requests.
Anything else will get REQUEST_DENIED errors.

This error sounds like you have generated a browser key rather than an iOS key. Try generating an iOS key in the Cloud Console and make sure that your bundle ID is whitelisted.

Related

IOS app to display values via BLE from an ESP32

I have an ESP32 Battery monitor system (BMS) whose status I want to view on an iPhone, there are about 100 values to be monitored with a maximum update rate of once per second. I also needs to be able to send settings to the BMS occasionally.
Blynk seemed to be the perfect app to do this but the new version 2.0 doesn't support BLE! Does anyone know a similar app that could do this?
Have you tried setting the ESP32 up as a web server and creating an API based on the values? Using this instead of bluetooth allows you to view the values from anywhere with internet connection, and is easier to implement and use across different platforms
You can do this by implementing code into the ESP32, so that when you make http requests, it returns with a value, just like any other API would. Then in Xcode where you are building your IOS app you can make http requests to the web server and retrieve values
for example, in the ESP32 you can do something like this (assuming you are using the Arduino IDE to program it):
server.on("/value", [](AsyncWebServerRequest * request))
{
String value = "value"
request->send(200,"text/plain", value)
}
This YouTube video shows you this in more detail: https://www.youtube.com/watch?v=cWZP7Y8qP6E
Then, in Xcode you can implement something along the lines of:
func loadData() async {
guard let url = URL(string: "http://IP-address-of-esp32/path-of-value", ) else {
print("Invalid URL")
return
}
do {
let (data, _) = try await URLSession.shared.data(from: url)
// process data here with the 'data' variable
} catch {
print("Invalid Data")
}
}
//Be aware that this is asynchronous when calling it
This person also explains it in more detail in a YouTube video: https://www.youtube.com/watch?v=MBCX1atOvdA
Now, since you have a web server and API set up on your ESP32, and a method of retrieving the values in your IOS app, you can go on and use the values to build the app to your liking.
Good Luck!

Share video to Facebook via Graph iOS SDK

I try to upload video to Facebook using Graph API.
But always see error message
(#100) No permission to publish the video.
Facebook app has Development mode. I created test user there. My role is admin. FB access token is valid.
Here my code here:
private func upload(url: URL) {
guard let data = try? Data(contentsOf: url) else { return }
let connection = GraphRequestConnection()
connection.delegate = self
var items: [String: Any] = [:]
items["title"] = "Test title from api"
items["\(url.absoluteString)"] = data
let keys = ["value" : "EVERYONE"]
items["privacy"] = keys
let request = GraphRequest(graphPath: "me/videos", parameters: items, httpMethod: .post)
connection.add(request) { reqconnection, anyInfo, error in
print(reqconnection)
print(anyInfo)
print(error)
}
connection.start()
}
I saw a lot of questions about it, but mostly they are too old and don't work for me.
Share video to FB
From thread FB Developers here - the same error, but they didn't find solution
Also check this docs - doesn't work
Also I'm a bit confused what docs are right for post video in Facebook.
Because in docs I see
The Video API allows you to publish Videos on Pages and Groups. Publishing on Users is not supported.
but also in another docs see Graph API with path me/videos. So it confused me a bit.
What docs are correct for my case:
here
here
From docs I see that
Your app should manage permissions as follows:
Graph API Requests - Before you send Graph API requests, you should check for necessary permissions and request them if needed.
Where can I find permission publish_actions?
Please help to figure out how to fix that.
I only can upload via ShareDialog. Like here and docs here

Why am I getting error code 403 while trying to fetch google+ profile image from my ios app?

I have a google iD of some user and I want to display his google profile photo in my app. In my swift code I try to fetch the json with necessary information (based on this answer https://stackoverflow.com/a/22526130/3766930 ). This is my code:
Alamofire.request(.GET, "https://www.googleapis.com/plus/v1/people/10263...4252?key=AI...Oo")
.responseJSON { response in
print(response)
switch response.result {
case .Success:
dispatch_async(dispatch_get_main_queue(),{
if let jsonData = response.result.value as? [[String: AnyObject]] {
print(jsonData)
}
})
case .Failure(let error):
print("SWITCH ERROR")
print(error)
}
}
but as a response I'm getting this error:
error = {
code = 403;
errors = (
{
domain = usageLimits;
extendedHelp = "https://console.developers.google.com";
message = "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 API key configuration if request from this IP or referer should be allowed.";
reason = ipRefererBlocked;
}
);
message = "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 API key configuration if request from this IP or referer should be allowed.";
};
I went carefully through my google developers console and I don't have any IP restrictions set up. This is how it looks so far:
I'm using the api key from here:
as you can see there is no domain limitation here:
What might be the reason of this weird error?
Remove the iOS bundle identifier restrictions for the API key in Google Developers Console. The bundle identifier restrictions only work when you use the Google client libraries.

Facebook get number of likes on custom object without login

I am using og.likes to like custom object from my app, with the help of Facebook-iOS sdks. I am able to like object and also read the like.
Now I want to know if there is any way in graph API that, I can show total number of likes on an object to a user who is not logged in to our app via Facebook ? i.e without access token
As per FB developer docs:-
https://developers.facebook.com/docs/graph-api/reference/v2.3/object/likes
It is mentioned that you need the same permissions required to view the parent object are required to view likes on that object, means an user access token with read_stream permission is required.
NOTE:
But if a user want to get the no of likes for Facebook page or profile or object , then it can be easily done by this:-
https://graph.facebook.com/< your object id>/
Then you will receive json response with Like Count:-
{
"id": "12345",
"link": "http://www.facebook.com/pages/MY iOS Page/102445859460201",
"likes": 150,
"type": "page"
}
Code:-
let url = NSURL(string: "http://graph.facebook.com/"+ObjectID)
let urlRequest = NSURLRequest(URL: url!)
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (response:NSURLResponse!, data:NSData!, error:NSError!) -> Void in
// Fetch the data
var jsonDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary
let likesCount = jsonDictionary["likes"] as? String
}
Got Response from Facebook Team :
Since Graph API v2.0, all requests to the API require an access token.
You can proxy this request through a web-server and use your app
access token for example.
You could as well make the request from your app by shipping your app
access token with the app, but I highly advise against this as the app
token should be kept secret.
Please note that the SDK does not support using the app access token
for security reasons. So you have to write your own networking code to
fetch this data.
I got the solution from
How to get Likes Count when searching Facebook Graph API with search=xxx
Here in this link it's not the exact solution but i have tried my way and unfortunately it worked for me, and i am quite satisfied with it, still using it in my application.
https://graph.facebook.com/v2.1/{Object-id}?fields=likes.summary(true)
You will need an access token, no need to login any user, you can generate an APP Access token to get that info .
jQuery.get("https://graph.facebook.com/oauth/access_token", {
'grant_type': "client_credentials",
'client_id': "000000000000000",
'client_secret': "0000000000000000000000000000000000"
}, function (data) {
// data is the app access token you will need for calling graph api
});
Thats more complicated but solves the necessity to login the user to get public informations from the graph .

How do I use the YouTube Data API in my iOS app? I get "Access not configured" error on each request

I want to use the YouTube Data API to get the links to thumbnails for a specific YouTube video in my iOS app. I went to Google Developers Console and created a new project.
For that project I then went to "APIs" and removed the default APIs it enables for me and added the YouTube Data API. I then went to credentials, created a Public Key (as I don't need the user to log in or anything, just getting the thumbnail URLs) as iOS, which gave me an API key. I added the Bundle Identifier for my project under Allowed Applications.
Now in my app I tried the following code:
let test = NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: "https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=*MYKEYHERE*&part=snippet,contentDetails,statistics,status")!, completionHandler: { (data, response, error) -> Void in
let json = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil)
println("JSON: \(json)")
})
But it prints out the error:
JSON: Optional({
error = {
code = 403;
errors = (
{
domain = usageLimits;
message = "Access Not Configured. Please use Google Developers Console to activate the API for your project.";
reason = accessNotConfigured;
}
);
message = "Access Not Configured. Please use Google Developers Console to activate the API for your project.";
};
})
What exactly am I doing wrong?
There is a known problem about Bundle id in the console. If you can just remove that restriction, it should just work fine.
You can track the original issue from here: https://code.google.com/p/gdata-issues/issues/detail?id=5770
Here's what you need, YouTube has a service API via web to consult this types of things. I'm using this URL to consult all videos from a user (getting every videos: URL, Thumbnail, views, duration, etc). I'm sure you'll find thumbnails for a particular video. Its a JSON response so you'll have to take a good look to the structure but can't get simpler than this.
http://gdata.youtube.com/feeds/api/users/USER_NAME/uploads?v=2&alt=json&#&start-index=1&max-results=10

Resources