View datastudio report by using service account key in simple flask app

Viewed 45

I have created a simple flask app with basic html page.

app.py

from flask import Flask, render_template, redirect, url_for
 
# Flask constructor takes the name of
# current module (__name__) as argument.
app = Flask(__name__)

@app.route('/')
# '/' URL is bound with hello_world() function.
def hello_world():
    return render_template('index.html') # index.html have embeded report from datastudio (method 1 to access report)

@app.route('/report')
def view_report():
    return redirect('datastudio report url') # method 2 shared link, any user can view report who has that link
 
# main driver function
if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8080, debug=True)

templates/index.html


    <!DOCTYPE html>
    <html>
    <body>
    <h1>Datastudio Test</h1>
    <p>Datastudio Report</p>
    <button type="submit" onclick='{view_report}' value="editor"></button>
    <!-- add embed code in next line : replace next line -->
    <iframe width="600" height="800" src="url to report" frameborder="0" style="border:0" allowfullscreen></iframe>
    </body>
    </html>

Webpage looks like this :Webpage look something like this

But I need to access the report by using service account key at application level. Idea behind that is anyone with valid key can access the report. If user have invalid key then it should return error message. To create report I have created a basic table in bigquery and link that to datastudio to generate report.

Please suggest solution with steps. Thank you in advance.

0 Answers
Related