0

I can't seem to get the EMBED-API Server-side Authorization demo to work: https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/

In the demo it says the following:

Once the library is installed you can add the following python module to your project and invoke the get_access_token() method to get an access token that you can use to authorize the Embed API.

# service-account.py  
from oauth2client.service_account import ServiceAccountCredentials
# The scope for the OAuth2 request.
SCOPE = 'https://www.googleapis.com/auth/analytics.readonly'
# The location of the key file with the key data.
KEY_FILEPATH = 'path/to/json-key.json'
# Defines a method to get an access token from the ServiceAccount object.
def get_access_token():
return ServiceAccountCredentials.from_json_keyfile_name(
KEY_FILEPATH, SCOPE).get_access_token().access_token

I've succesfully done all the previous steps, but this one I just can't get my head around. Where do I put this code? It seems as if it should be put in a .py file.

Can someone please help?

2 Answers2

0

It depends on your implementation, but basically you want to run your service account code on your server, and have the access token passed to your client application so it can make authorized requests from the browser.

The whole app is open sourced and you can see where the service account code is in the source code.

As in the demo, if you are using django or app engine it is easy to put python server code in your site which will return the token and replace the value in template code.

Matt
  • 5,028
  • 2
  • 28
  • 55
  • Thank you Matt. I just want to make a dashboard on my website: http://web-tailor.nl/dashboard/ this dashboard works now, but I want it to have a fixed view without the need to log in. Is there a way to implement this? I'm a bit of a noob, but I don't have a server. – PaulusfranCircus Jul 14 '16 at 19:29
  • Without a server it would be impossible to make use of a [service account](https://developers.google.com/identity/protocols/OAuth2ServiceAccount). Make a careful study of the various [OAuth 2.0 Scenarios](https://developers.google.com/identity/protocols/OAuth2#scenarios). A service account needs a secure place to run. – Matt Jul 14 '16 at 21:25
0

Add that code in service-account.py file and upload it on your server using FTP. I saved the code using dreamweaver, updated the path and added following line at the end of the service-account.py file:

print get_access_token()

Upload .JSON file in same directory and ran the command python service-account.py to get access_token.

miva2
  • 2,111
  • 25
  • 34
Ali Jaffri
  • 11
  • 1