作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建再营销名单。我阅读了已安装应用程序的 Python 快速入门,并使用了其中的代码。我是 python 新手。代码如下:
from __future__ import print_function
import argparse
import sys
from googleapiclient.errors import HttpError
from googleapiclient import sample_tools
from oauth2client.client import AccessTokenRefreshError
from oauth2client import tools
from apiclient.discovery import build
import httplib2
from oauth2client import client
from oauth2client import file
def get_service(api_name, api_version, scope, client_secrets_path):
"""Get a service that communicates to a Google API.
Args:
api_name: string The name of the api to connect to.
api_version: string The api version to connect to.
scope: A list of strings representing the auth scopes to authorize for the
connection.
client_secrets_path: string A path to a valid client secrets file.
Returns:
A service that is connected to the specified API.
"""
# Parse command-line arguments.
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
parents=[tools.argparser])
flags = parser.parse_args([])
# Set up a Flow object to be used if we need to authenticate.
flow = client.flow_from_clientsecrets(
client_secrets_path, scope=scope,
message=tools.message_if_missing(client_secrets_path))
# Prepare credentials, and authorize HTTP object with them.
# If the credentials don't exist or are invalid run through the native client
# flow. The Storage object will ensure that if successful the good
# credentials will get written back to a file.
storage = file.Storage(api_name + '.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = tools.run_flow(flow, storage, flags)
http = credentials.authorize(http=httplib2.Http())
# Build the service object.
service = build(api_name, api_version, http=http)
return service
def create(service):
return service.management().remarketingAudience().insert(
accountId='16694538',
webPropertyId='UA-16694838-1',
body={
'name': 'Simple Audience',
'linkedViews': 33205313,
'linkedAdAccounts': [{
'type': 'ADWORDS_LINKS',
'linkedAccountId': '518-659-6088'
}],
'audienceType': 'SIMPLE',
'audienceDefinition': {
'includeConditions': {
'isSmartList': False,
'daysToLookBack': 7,
'membershipDurationDays': 30,
'segment': 'users::condition::ga:browser==Chrome'
}
}
}
).execute()
def main():
# Define the auth scopes to request.
scope = ['https://www.googleapis.com/auth/analytics.edit']
# Authenticate and construct service.
service = get_service('analytics', 'v3', scope, 'client_secrets.json')
profile = '33205313'
create(service)
if __name__ == '__main__':
main()
我收到如下错误:
Traceback (most recent call last):
File "/home/maciek/Documents/HelloAnalytics.py", line 88, in <module>
main()
File "/home/maciek/Documents/HelloAnalytics.py", line 84, in main
create(service)
File "/home/maciek/Documents/HelloAnalytics.py", line 71, in create
'segment': 'users::condition::ga:browser==Chrome'
File "/usr/local/lib/python2.7/dist-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/googleapiclient/http.py", line 840, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/analytics/v3/management/accounts/16694838/webproperties/UA-16694838-1/remarketingAudiences?alt=json returned "Insufficient Permission">
[Finished in 0.7s with exit code 1]
请告诉我如何让它发挥作用。
最佳答案
我想是因为您没有调用函数 get_service 来返回使用 API 所需的服务对象。当然,这段代码还没有“准备好”,但一定要让快速入门有更好的外观。
service = get_service('analytics', 'v3', scope, key_file_location,
service_account_email)
这是“分析”服务的示例。这是quickstart供您引用
关于python - 使用 API 创建再营销名单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43222765/
我有本地更改和远程更改。 有人告诉我必须先推,再 pull 。这背后有什么原因吗? 最佳答案 那个人错了:正确的模型是pull-before-you-push,而不是相反。 当您pull时,git 将
我正在使用最新版本的 Flat UI Pro 1.3.2 ( http://designmodo.com/flat/ ),jQuery 插件 flatui-radiocheck v0.1.0 和 iO
我是一名优秀的程序员,十分优秀!