0
리 마케팅 목록을 만들려고합니다. 나는 설치된 응용 프로그램에 대한 파이썬 빠른 시작을 읽고 거기에서 코드를 사용했습니다. 저는 파이썬 초보자입니다. 여기 코드는 다음과 같습니다API를 사용하여 리 마케팅 목록 만들기
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 함수를 호출했습니다. 이제 새로운 오류가 발생합니다. – TityBoi
자세한 내용은이 답변을 참조하십시오. http://stackoverflow.com/questions/16978192/google-plus-api-insufficientpermissions-error. 또한 귀하의 계정이 https://developers.google.com/analytics/devguides/config/mgmt/v3/remarketing에 나열된 모든 요구 사항을 충족하는지 확인하십시오. – Igneel64