Access Google ML engine by iOS application - google-app-engine

I followed the following documentation by Google to create ML engine and I deployed my online predicator there:
https://cloud.google.com/ml-engine/docs/scikit/quickstart
Now my question is what is the simplest way I can connect my iOS application to the prepared ML engine?

You can request Online Predictions, the quickstart provides how to request online predictions by using either the gcloud tool or the python client library, but you can also use a HTTP Request to the JSON API to get the predictions by using the projects.predict method [1]:
POST https://ml.googleapis.com/v1/{name=projects/**}:predict
You just have to add your request body with your list of instances using this JSON format [2]:
{
"instances": [
<simple list>,
...
]
}
[1] https://cloud.google.com/ml-engine/reference/rest/v1/projects/predict
[2] https://cloud.google.com/ml-engine/docs/v1/predict-request#request-body

Related

"status code 403" Error while creating file using Mule 4 google drive connector

I have to upload images to google drive through mule integration. I'm facing trouble with <google-drive:file-content> connector. Can someone help me or direct me a tutorial relates to it?
This is the error message while I tried to connect to the google drive
Message : Request returned status code 403
Element : imageuploaderFlow/processors/4 #
imageuploader:imageuploader.xml:39 (Create media file)
Element DSL : <google-drive:create-media-file doc:name="Create media file" doc:id="hhhhhjhj" config-ref="Google_Drive_Connector_Config" contentType="application/octet-stream">
<google-drive:file-content><![CDATA[
#[payload.parts.image.content write "application/octet-stream"]
]]></google-drive:file-content>
</google-drive:create-media-file>
Error type : GOOGLE-DRIVE:CLIENT_ERROR
FlowStack : at imageuploaderFlow(imageuploaderFlow/processors/4 # imageuploader:imageuploader.xml:39 (Create media file))
Google Drive Connector Config
scopes: https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file
connector xml snippet
<google-drive:create-media-file doc:name="Create media file" doc:id="ac59e7fe-e615-fggh-9473-2we5cd73ecb7" config-ref="Google_Drive_Connector_Config" contentType="application/octet-stream">
<google-drive:file-content ><![CDATA[#[payload.parts.image.content write "application/octet-stream"]]]></google-drive:file-content>
</google-drive:create-media-file>
The version of the Google Drive connector is 1.0.1
Ensure that you have Enabled the Google Drive API in your project. Not enabling this also raises a 403 error. Also, mostly, Google API sends pretty clear message when you do something wrong. You can access the detailed HTTP response using error.errorMessage.payload and headers using error.errorMessage.attributes.headers

Agora Analytics (BETA) Rest API does not work for route /analytics/call/lists route

When making a GET request (through Postman) at "https://api.agora.io/beta/analytics/call/lists" with query parameters:
appid (following the official documentation, i base64 encoded {Customer ID}:{Customer Secret} string)
start_ts (timestamp format e.g. 1627990383)
end_ts (timestamp format e.g. 1628163183)
When I make the request, i get a response with status 200 OK, but the response body is the following :
{
"code": 500,
"message": "Unknown error"
}
I set the headers as mentioned in the official documentation :
Has anyone got a legit response from this request? And what was his request construction?
I have the same problem. I asked the support what to do, this is what they answered me:
The analytics restful API you are trying to use is part of the
Enterprise support package and requires that for you to be able to use
them. We do have something in the works for cheaper analytics later
down on the line so if you do want to purchase a package for restful
APIs for analytics, please let us know and we can put you in contact
with a CSM.
I think this functionality is supported only in the Enterprise version of the package.

Google App Engine Algolia Indexing Error

I’m using Google App Engine for a golang api with algolia and I’ve been working (indexing records) without any issue in localhost, today I deployed to test it live and I got this error for all my indexing operations
Cannot perform request [POST] /1/indexes/INDEXNAME/batch (APPID.algolianet.com): Post https://APPID.algolianet.com/1/indexes/INDEXNAME/batch: dial tcp: lookup APPID.algolianet.com on [::1]:53: dial udp [::1]:53: socket: operation not permitted
Any solution ideas?
I struggled with setting up algolia with app engine in production, you have to set up a different transport for the algolia client... here is it:
client := algoliasearch.NewClient(ALGOLIA_APP_ID, ALGOLIA_API_KEY)
transport := &http.Client{
Transport: &urlfetch.Transport{
AllowInvalidServerCertificate: true,
Context: appengine.NewContext(r), // r *http.Request
},
}
client.SetHTTPClient(transport)
client.initIndex(INDEX_NAME)
EDIT:
This is now fixed by golang 1.11 release, you can simply use algolia golang as is

Google Cloud Pubsub authentication error from App Engine

We're having trouble publishing messages to a Google Cloud PubSub topic on Google AppEngine. Using the Application Default credentials works perfect locally. But once it's deployed on Google AppEngine it gives the following error:
<HttpError 403 when requesting https://pubsub.googleapis.com/v1/projects/our-project-id/topics/our-topic:publish?alt=json returned "The request cannot be identified with a project. Please pass a valid API key with the request.">
I would assume that it's will use the service account of app engine to access the PubSub API. Here is the code we used to create the credentials.
credentials = GoogleCredentials.get_application_default()
if credentials.create_scoped_required():
credentials = credentials.create_scoped(['https://www.googleapis.com/auth/pubsub'])
http = httplib2.Http()
credentials.authorize(http)
pubsub_service = build('pubsub', 'v1', http=http)
The error is thrown when publishing the actual message to PubSub.
pubsub_service.projects().topics().publish(topic="projects/out-project-id/topics/out-topic", body = { 'messages' : [ { 'data': base64.b64encode(request.get_data()) }]}).execute()
Not that the same flow works doing API call's to "BigQuery", so it's not a general Google API problem. It seems to be specific to PubSub...
It's a rare case of the service account without project id embedded in it. We fixed your service account and you should be good to go now. Sorry for the trouble.

Cloud Endpoints HTTP Cookies

I am implementing Cloud Endpoints with a Python app that uses custom authentication (GAE Sessions) instead of Google Accounts. I need to authenticate the requests coming from the Javascript client, so I would like to have access to the cookie information.
Reading this other question leads me to believe that it is possible, but perhaps not documented. I'm not familiar with the Java side of App Engine, so I'm not quite sure how to translate that snippet into Python. Here is an example of one of my methods:
class EndpointsAPI(remote.Service):
#endpoints.method(Query_In, Donations_Out, path='get/donations',
http_method='GET', name='get.donations')
def get_donations(self, req):
#Authenticate request via cookie
where Query_In and Donations_Out are both ProtoRPC messages (messages.Message). The parameter req in the function is just an instance of Query_In and I didn't find any properties related to HTTP data, however I could be wrong.
First, I would encourage you to try to use OAuth 2.0 from your client as is done in the Tic Tac Toe sample.
Cookies are sent to the server in the Cookie Header and these values are typically set in the WSGI environment with the keys 'HTTP_...' where ... corresponds to the header name:
http = {key: value for key, value in os.environ.iteritems()
if key.lower().startswith('http')}
For cookies, os.getenv('HTTP_COOKIE') will give you the header value you seek. Unfortunately, this doesn't get passed along through Google's API Infrastructure by default.
UPDATE: This has been enabled for Python applications as of version 1.8.0. To send cookies through, specify the following:
from google.appengine.ext.endpoints import api_config
AUTH_CONFIG = api_config.ApiAuth(allow_cookie_auth=True)
#endpoints.api(name='myapi', version='v1', auth=AUTH_CONFIG, ...)
class MyApi(remote.service):
...
This is a (not necessarily comprehensive list) of headers that make it through:
HTTP_AUTHORIZATION
HTTP_REFERER
HTTP_X_APPENGINE_COUNTRY
HTTP_X_APPENGINE_CITYLATLONG
HTTP_ORIGIN
HTTP_ACCEPT_CHARSET
HTTP_ORIGINALMETHOD
HTTP_X_APPENGINE_REGION
HTTP_X_ORIGIN
HTTP_X_REFERER
HTTP_X_JAVASCRIPT_USER_AGENT
HTTP_METHOD
HTTP_HOST
HTTP_CONTENT_TYPE
HTTP_CONTENT_LENGTH
HTTP_X_APPENGINE_PEER
HTTP_ACCEPT
HTTP_USER_AGENT
HTTP_X_APPENGINE_CITY
HTTP_X_CLIENTDETAILS
HTTP_ACCEPT_LANGUAGE
For the Java people who land here. You need to add the following annotation in order to use cookies in endpoints:
#Api(auth = #ApiAuth(allowCookieAuth = AnnotationBoolean.TRUE))
source
(Without that it will work on the local dev server but not on the real GAE instance.)

Resources