Python 试图从谷歌DFA报告工具获取数据?

Python 试图从谷歌DFA报告工具获取数据?,python,google-oauth,google-dfp,Python,Google Oauth,Google Dfp,每次我需要复制和粘贴控制台中生成的代码时,我都会尝试从Google获得oauth! 我想让它自动化? 知道我该怎么做吗 我有这个密码 DFA\u USER\u PROFILE\u NAME='MYPROFILE\u NAME' 范围= ["https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/dfareporting“] 除BaseException外,如e: 打印“这确实是发

每次我需要复制和粘贴控制台中生成的代码时,我都会尝试从Google获得oauth! 我想让它自动化? 知道我该怎么做吗

我有这个密码

DFA\u USER\u PROFILE\u NAME='MYPROFILE\u NAME'

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

除BaseException外,如e:
打印“这确实是发生的错误”,e

我正在努力,但我不知道哪里出了问题

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

请尝试以下操作-它会在第一时间提示您,但随后会将凭据写入磁盘并将其读入以供后续调用:

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)

我们有一个方法放在这里,我们如何使用代码?存储凭据并使用GET方法。如何创建.dat文件?在这种情况下,.dat文件会在第一次运行时自动创建。可以忽略最后两行,只需按原样使用http对象,这应该适用于GET和PUT请求。
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)