Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticating with service account in Python3 #27

Open
dtgnn opened this issue Feb 11, 2016 · 3 comments
Open

Authenticating with service account in Python3 #27

dtgnn opened this issue Feb 11, 2016 · 3 comments
Labels

Comments

@dtgnn
Copy link

dtgnn commented Feb 11, 2016

I am trying to run queries on my google analytics project. I use python3 and I authenticate using the p12 key associate to my service account. I ran into few issues and I was hoping to get some feedback.

After reading the wiki, I installed pycrypto and attempted to authenticate with:
ga.authenticate(client_email=client_email, private_key=private_key)

  1. parsing the p12 key didn't work. I solved that removing pycrypto and installing the cryptography library.
  2. assigning the value of private_key I stumbled into an encoding problem:
private_key=self.private_key.encode('utf-8'),
AttributeError: 'bytes' object has no attribute 'encode' 

I solved it modifying this line to remove the encode('utf-8) call.

And now I'm stuck. ga.authenticate returns a googleanalytics.account object, containing a single account, however I don't know how to get from there to the profile I need to run my queries. Any idea?

@debrouwere
Copy link
Owner

Thanks for the feedback, I'll have to revamp the service account authentication one of these days – many of the underlying libraries have changed since I wrote it, so it's not surprising that it doesn't work anymore.

As for getting to your profile from your account, that's no different from any other account object: account.webproperties['my_property'].profiles['my_profile']. Alternatively you can add profile and webproperty arguments to ga.authenticate. If you're not sure which properties are available, just do account.webproperties and you should get a list.

Review the documentation at https://github.com/debrouwere/google-analytics/wiki/Authentication and let me know if anything is unclear.

@debrouwere debrouwere added the bug label Feb 12, 2016
@dtgnn
Copy link
Author

dtgnn commented Feb 18, 2016

Thanks for your reply. Your first suggestion seemed to do the trick for me.

On Fri, Feb 12, 2016 at 3:30 AM, Stijn Debrouwere [email protected]
wrote:

Thanks for the feedback, I'll have to revamp the service account
authentication one of these days – many of the underlying libraries have
changed since I wrote it, so it's not surprising that it doesn't work
anymore.

As for getting to your profile from your account, that's no different from
any other account object:
account.webproperties['my_property'].profiles['my_profile'].
Alternatively you can add profile and webproperty arguments to
ga.authenticate. If you're not sure which properties are available, just
do account.webproperties and you should get a list.

Review the documentation at
https://github.com/debrouwere/google-analytics/wiki/Authentication and
let me know if anything is unclear.


Reply to this email directly or view it on GitHub
#27 (comment)
.

@thenaturalist
Copy link

thenaturalist commented Mar 20, 2018

I am unable to get this to work. None of the steps by @dtgnn worked for me.
Installed pycrypto, pyOpenSSL as well as cryptography and always get CryptoUnavailableError: No crypto library available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants