How to combine Google App Engine with Cloud Natural Language - python

I thought what I was trying to do would be simple, but that seems to not be the case.
I've found that using the Natural Language API with Google Compute Engine is fairly straightforward, as I can simply import the needed libraries in Python.
This does not seem to be the case with App Engine, as I am plagued by import errors, as soon as I fix one, another arises.
Have any of you ever worked to combine these two services, and if so, how?
Thank you

App Engine Standard does not yet support Google Client Libraries (which I assume you are trying to import into your application), it is work in the development, so by now you can try with the following alternatives:
App Engine Flexible: it does support Client Libraries, you just have to vendor them into your application as if they were third-party libraries. You can follow this guide in order to add the google-api-python-client library appropriately.
REST API: you can use the REST API (which already has a stable version, v1). It might not be as convenient as Client Libraries, but you can make HTTP requests with your Python code and process their responses.
Compute Engine: as you pointed out in your question, you will be able to use Client Libraries from your custom Python runtime environment in any machine you want (either locally or an instance in Compute Engine).
UPDATE:
Actually, I have looked deeper into your issue and have been able to solve it using App Engine Standard by using the Google API Client Library (not Google Client Libraries), which is an alternative version that is available for the Standard environment. Below I leave a small working piece of code which you can populate with your own data and try in App Engine environment or even with the Local Development server.
from apiclient.discovery import build
service = build('language', 'v1', developerKey='<YOUR_API_KEY>')
collection = service.documents()
data = {}
data['document'] = {}
data['document']['language'] = 'en'
data['document']['content'] = 'I am really happy'
data['document']['type'] = 'PLAIN_TEXT'
request = collection.analyzeSentiment(body=data)
res = request.execute()
You will have to obtain an API key for authentication, as explained in the documentation, and you will also need to add the library as explained in the other link I shared.
Last, here you have the documentation on the available methods from the API. The example I provided is using analyzeSentiment(), but you can go with the one you need.
Hope it helps!

Related

Open API specification and App Engine Endpoints

I have developed an API on App Engine using the endpoints-proto-datastore library. At this point I am exploring the use of Swagger to create an Endpoints specification, and am not sure how to proceed. Support for this is indicated in Google's Endpoints docs, but there's not much to get started, particularly for Python.
If possible, I'd like to continue using just the endpoints library and webapp rather than going to Flask which seems like overkill. Any hints for how one might thus proceed?

Which Python Cloud Storage lib/API is "officially" supported by Google?

I'm migrating a Python service out of Google App Engine over to GCE/GKE and could use some help identifying the current production-grade, SLA'd method for managing objects in Google Cloud Storage.
The one referenced by most of Google's storage docs is the google.cloud.storage library. This looks nice and simple. However, as of now -- Jan 2017 -- there's a big header at the top that identifies the library as Beta, and has no SLA or deprecation policy. I'd prefer to use an SLA'd service.
After a lot of searching I found this alternative JSON API example:
https://github.com/GoogleCloudPlatform/storage-file-transfer-json-python
but it's much more cumbersome and isn't clear that it's better supported.
Any advice on which API to use?
Or better examples for bootstrapping?
Thanks in advance
Google Cloud Storage, the service, is not in beta. It has an SLA and a deprecation policy. The client library you've found, the Google Cloud Client Library for Python (google-cloud), is in beta, which means that it's possible that a future version of it might in some cases make backwards-incompatible changes. However, it's also the current gold standard for easiest-to-use client library.
I recommend you use that one. Another option is the Google Python API Client Library, which is not in beta, but I found the Google Cloud Client Library for Python to be substantially easier to use, which is important.

Google plus authentication on Google App Engine Python Example

I read tons of documentations, but I cannot find e real full-working example of a Python Google App Engine that simply gives a Login/Logout button to the GOOGLE PLUS authentication system.
Probably this is due to my limited understanding.
My need is to use the info on the backend side in order to give customized contents.
Maybe that's because apparently Google+ Sign-In is being phased out, replaced by Google Sign-In: https://developers.google.com/identity/sign-in/web/quick-migration-guide.
If you're just starting it's probably better to go directly to the newer method (or maybe check if other alternatives might be available/better fitted for your app: https://developers.google.com/identity/) then re-focus your searches accordingly.
Also very important (for most if not all newer authentication methods) - pay attention to the implementation guides:
no code example will be working out of the box as various application-specific service configurations are usually needed as well
no code example will be complete since it needs to incorporate application-specific keys or other pieces of info that can only be obtained from the above service configurations
At the end I solved the problem using simpleauth.
https://simpleauth.appspot.com/
Surely the easyest and efficient way to add oauth2 authentication in your website.

Google Cloud Endpoints discovery document changes / evolution support on iOS?

I'm implementing the iOS client-side of our Google Cloud Endpoints API, and want to know how Cloud Endpoints discovery documents get interpreted internally on iOS, so when I make changes on the Cloud Endpoints side (add a field, change a field name, delete a field) what happens to older clients?
I know that Cloud Endpoints exposes a REST JSON API for the Javascript/AngularJS side of things which we could tie into manually using something like AFNetworking on iOS. I'm familiar with how to manage API changes on the client in that scenario, but if it makes sense to utilize the Toolkit SDK / RPC implementation, then I'd rather do that.
Is this all handled by versioning the API, then? So older clients would request an older version of the API? Does the Google iOS SDK support semantic versioning then? I could see version numbers getting out of control quickly if not.
Note this is the python version of GCE.
You should be generating and using a client library, ultimately, if you don't want to both yourself with all kinds of implementation details of how to call the endpoints API. On the other hand, if you were to go with AFNetworking, it would be up to you do do your research as to how REST APIs can be called with AFNetworking. The REST API defined by endpoints can be read about in the documentation, and in addition you can use the API Explorer to test your methods and even capture the headers sent with these requests in your browser.
Secondly, it goes without saying that you shouldn't code an API, then change its specs radically without versioning it or notifying/updating any clients. The version system is implemented A) in the client library generated from your discovery doc and B) in the URL route of the REST API itself. You would want to choose whichever naming scheme for versioning that your target framework supports.
I hope this has cleared up any confusion for you.

Google Apps Python provisioning API & OAuth mess

I'm trying to provision (among other things) groups for our Google Apps domain, using python. I'm also attempting to using OAuth to authorise my application. The API documentation for Python seems to be missing or broken links. But from searching through the code, it seems I can't use the new (GDClient) APIs as (among other things) I can't get a list of group owners (which I can do in the older GDataService API). And the API for group settings seems to be either the old GDataService, or the even newer apiclient API, but I can't perform basic group provisioning using that API. So it seems I'm stuck using the GDataService API. However, I can't get my head around how to use OAuth for GDataService objects - I can create an oauth token using oauth2client, but can't authorise a GDataService object using this token.
Any pointers as to where to go from here? I'm struggling to believe how messy this all is
The provisioning API is still on the older GDataService API. It is being replaced by the new API called directory api (check out here https://developers.google.com/admin-sdk/)
If you just want to at least get start and familiar with the OAuth flow. You should check out this documentation for the Python API client library: https://developers.google.com/api-client-library/python/start/installation
Try the quick start. All you have to do is select the API you want to use, and select the platform (I usually just picked command line). Click 'Configure Project'. Make sure you are already logged in you Google Apps account that you used to create your project in API console. Select your API project and then finally download the whole package.
Remember to replace your client secret file and just run the sample python code. It will do all the OAuth flow for you.

Categories

Resources