【问题标题】:Trying to get the data from google DFA reporting tool?试图从谷歌 DFA 报告工具中获取数据?
【发布时间】:2013-12-20 06:27:36
【问题描述】:

我正在尝试从 Google 获取 oauth,每次我需要在我的控制台中复制并粘贴生成的代码时都经过身份验证! 我想让它自动化吗? 知道我该怎么做吗?

我有这个代码!

DFA_USER_PROFILE_NAME='MYPROFILE_NAME'

scope = ["https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/dfareporting"]

try:

   redirect_uri=redirect_uri='urn:ietf:wg:oauth:2.0:oob'
   flow=flow_from_clientsecrets('Location of the json file', scope, redirect_uri, message)
   authorize_url = flow.step1_get_authorize_url()
   self.redirect(authorize_url)
   credential = flow.step2_exchange(self.request.params)
   storage=StorageByKeyName(credentials,user.user_id(),'credentials'
                         )
   storage.put(credentials)
   user=user.get_current_user()

   credentials = client.oauth2credentials
   client.oauth2credentials = credentials
   http = httplib2.Http()

except BaseException as e: print "this is really a error that has occured ",e

我正在尝试但我不知道我哪里出错了?

什么是 self.params ? 这项服务在 Google Cloud 中是免费的吗?

【问题讨论】:

    标签: python google-oauth google-dfp


    【解决方案1】:

    尝试以下操作 - 它应该会在第一次提示您,然后将凭据写入磁盘并读取它们以供后续调用:

    import httplib2
    from oauth2client.file import Storage
    from oauth2client.client import flow_from_clientsecrets
    from oauth2client.tools import run_flow, argparser
    from apiclient.discovery import build
    
    storage = Storage("/path/to/saved_user_creds.dat")
    credentials = storage.get()
    if credentials is None or credentials.invalid:
      credentials = run_flow(flow_from_clientsecrets("/path/to/client_secrets.json", scope=["scope1" ,"scope2"]), storage, argparser.parse_args([]))
    http = credentials.authorize(httplib2.Http())
    
    # Use the http object as needed...
    service = build("bigquery", "v1")
    result = service.object().method(name=value).execute(http=http)
    

    【讨论】:

    • 我们有一个方法 PUT 我们如何在这里使用该代码?存储凭据并使用 GET 方法。如何创建 .dat 文件?在这种情况下?
    • 第一次运行时会自动为您创建 .dat 文件。随意忽略最后两行,直接使用 http 对象,它应该适用于 GET 和 PUT 请求。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 2020-03-02
    • 1970-01-01
    • 2019-10-31
    • 2012-06-06
    • 1970-01-01
    相关资源
    最近更新 更多