【问题标题】:How do I pass my Google Analytics API response with webapp2如何使用 webapp2 传递我的 Google Analytics API 响应
【发布时间】:2018-05-09 10:19:10
【问题描述】:

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

基本上,我正在尝试将 Google Analytics hello world python 教程与 Google App Engine 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 脚本的响应,而不是 class MainPage 函数中的 Hello World

谢谢!

【问题讨论】:

    标签: python webapp2


    【解决方案1】:

    解决方法如下:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-03
      • 1970-01-01
      相关资源
      最近更新 更多