Python 如何通过webapp2传递我的Google Analytics API响应

Python 如何通过webapp2传递我的Google Analytics API响应,python,webapp2,Python,Webapp2,我在这里学习,所以请对我好一点:) 基本上,我尝试将Google Analytics hello world python教程与Google应用程序引擎hello world python教程混合使用 Google Analytics python hello world以以下内容结束: def main(): analytics = initialize_analyticsreporting() response = get_report(analytics) print_resp

我在这里学习,所以请对我好一点:)

基本上,我尝试将Google Analytics hello world python教程与Google应用程序引擎hello world python教程混合使用

Google Analytics python hello world以以下内容结束:

def main():
  analytics = initialize_analyticsreporting()
  response = get_report(analytics)
  print_response(response)

if __name__ == '__main__':
  main()
Google App Engine Hello world教程有如下内容:

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, World!')
我的问题很简单。如何在
类主页
函数中打印Google Analytics脚本的响应而不是
Hello World


谢谢

以下是解决方案:

import json


class MainPage(webapp2.RequestHandler):
    def get(self):
        analytics = initialize_analyticsreporting()
        report = get_report(analytics)
        data = json.dumps(report)
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(data)