我试着使用youtube分析API。我已经将通道的访问令牌存储在某个db中。在Php中,您可以构建客户机,只需添加访问令牌、client_id、client_secret,然后使用客户机调用youtube分析。
然而,在python示例中,我看到了如下所示:
flow = flow_from_clientsecrets(
CLIENT_SECRETS_FILE,
scope=' '.join(YOUTUBE_SCOPES),
message=MISSING_CLIENT_SECRETS_MESSAGE)
storage = Storage('%s-oauth2.json' % sys.argv[0])
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = run_flow(flow, storage, data)
http = credentials.authorize(httplib2.Http())
yt.analytics = build(
YOUTUBE_ANALYTICS_API_SERVICE_NAME,
YOUTUBE_ANALYTICS_API_VERSION,
http=http)它使用浏览器验证用户的身份。我不需要这样做,因为我已经将access_token存储在数据库中了。问题是如何在access_token函数调用中使用该build(),以便继续下面的查询。
analytics_query_response = yt_analytics.reports().query(
ids='channel==',
metrics=options.metrics,
dimensions=options.dimensions,
start_date=options.start_date,
end_date=options.end_date,
max_results=options.max_results,
sort=options.sort,
).execute()发布于 2015-08-07 18:26:16
不幸的是,build函数没有access_token参数。这是文档。
您也可以像这样创建您的credentials对象(这可能是您要寻找的):
from oauth2client.client import GoogleCredentials
from oauth2client import GOOGLE_TOKEN_URI
access_token = YOUR_TOKEN
token_expiry = None
token_uri = GOOGLE_TOKEN_URI
user_agent = 'Python client library'
revoke_uri = None
credentials = GoogleCredentials(
access_token,
client_id,
client_secret,
refresh_token,
token_expiry,
token_uri,
user_agent,
revoke_uri=revoke_uri
)https://stackoverflow.com/questions/31870381
复制相似问题