Reputation: 1302
We have an iOS app that needs to connect to a Google App Engine Endpoint. The connection is done via Objective-C Google Api and the generated API from the App Engine Endpoint discovery file.
The code works well connecting to the appspot.com deployed application but we cannot manage to make a call to the local App Engine server running the same application.
The code to call the endpoint is (Swift code):
let myService = GTLServiceMyService()
self.myService.authorizer = GTMOAuth2ViewControllerTouch.authForGoogleFromKeychainForName(kKeychainItemName,
clientID: kClientID,
clientSecret: kClientSecret)
let query = GTLQueryMyService.queryForContentsGetContents() as GTLQueryMyService
query.orderBy = "NAME"
self.myService.executeQuery(query, completionHandler: { (ticket: GTLServiceTicket!, object: AnyObject!, error: NSError!) -> Void in
// Process the response
})
As I said the code is working but only with the appspot.com server, how to connect to the local server api?
http://localhost:8080/_ah/api
Also a Objective-C example is good for us.
Thanks you
Upvotes: 1
Views: 1387
Reputation: 11
regarding your question "As I said the code is working but only with the appspot.com server, how to connect to the local server api? "
Remember localhost on your phone refers to the phone's localhost which is different from your development machine's localhost. Localhost resolves to the IP address 127.0.0.1 (generally). So to connect to a locally running app engine instance you'll need to use that computer's IP address on your local network.
Upvotes: 0
Reputation: 1302
Just to help anyone with the same problem the solution is to put this code after setting the authorizer
object on myService
(using Swift):
(self.myService.authorizer as GTMOAuth2Authentication).shouldAuthorizeAllRequests = true
self.myService.retryEnabled = true
self.myService.fetcherService.allowLocalhostRequest = true
self.myService.rpcURL = NSURL(string: "http://localhost:8080/_ah/api/rpc?prettyPrint=false")
self.myService.apiVersion = "v1"
Upvotes: 2