PsychoinformaticsLab / pliers

Automated feature extraction in Python
https://pliers.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
296 stars 68 forks source link

google-api-python-client updates #473

Closed emdupre closed 2 years ago

emdupre commented 2 years ago

I'm seeing consistent errors for the Google API converters, that I think trace back to an updated internal API :

For example, when running the GoogleSpeechAPIConverter:

  File "/home/users/emdupre/miniconda3/envs/pliers/lib/python3.9/site-packages/pliers/converters/api/google.py", line 51, in _query_api
    request_obj = self.service.speech().recognize(body=request)
AttributeError: 'NoneType' object has no attribute 'speech'

Similarly for the GoogleVision APIs:

  File "/home/users/emdupre/miniconda3/envs/pliers/lib/python3.9/site-packages/pliers/transformers/api/google.py", line 98, in _query_api
    request_obj = self.service.images() \
AttributeError: 'NoneType' object has no attribute 'images'

Following this guide and its accompanying Python quickstart, I believe that google-api-python-client -- while still officially supported ! -- had a breaking change 2.0 release which affected private APIs such as those used here.

It's unfortunately still not obvious to me how to update the calls to google-api-python-client within the existing library structure, but I'd guess we need to update the build call here:

https://github.com/PsychoinformaticsLab/pliers/blob/df432abb11eb56950ca5cc67896f61e9c21f304b/pliers/transformers/api/google.py#L49-L51

following this comment.

Alternatively, a larger update would be to move to the Google Cloud Client libraries, as recommended in the google-api-python-client documentation.

Any input here -- to either patch the current calls or on potential paths forward -- would be appreciated !

emdupre commented 2 years ago

Good news : I was able to get this running by removing the discoveryServiceUrl param !

I also needed to update my JSON to not use OAuth (as I had done previously) but instead use a ServiceAccount key. Apparently this is not currently recommended for security reasons (😬 ), but it works. Here's the guide I followed : https://cloud.google.com/iam/docs/creating-managing-service-accounts

This is likely something I just overlooked from the existing documentation, but happy to send a PR with these changes if you think anyone else is likely to benefit from this !