使用 google 个 DFP 服务帐户
Use of google service account for DFP
我正在尝试使用 DFP 的服务帐户,但出现此错误
OpenSSL.crypto.Error: [('asn1 encoding routines', 'ASN1_D2I_READ_BIO', 'not enough data')]
我已经在 dfp 中添加了服务帐户并检查了已创建的服务帐户 email_id 但仍然无法解决问题
这是我的代码,有人可以帮我解决这个问题
from googleads import dfp
from googleads import oauth2
import logging
logging.basicConfig(filename='debug.log',level=logging.DEBUG)
# OAuth 2.0 credential information. In a real application, you'd probably be
# pulling these values from a credential storage.
SERVICE_ACCOUNT_EMAIL = '600632524044-6g7l2njp5g5ldd21j7eaolf1k15pdm1u@developer.gserviceaccount.com'
KEY_FILE = 'D:\DFP\GoogleDFP.p12'
# DFP API information.
APPLICATION_NAME = 'New Srevice Account'
def main(service_account_email, key_file, application_name):
# with open(key_file, 'rb') as f:
# private_key = f.read()
# f.close()
oauth2_client = oauth2.GoogleServiceAccountClient(
oauth2.GetAPIScope('dfp'), service_account_email, key_file)
client = dfp.DfpClient(oauth2_client, application_name)
inventory_service = client.GetService('InventoryService', version='v201505')
statement = dfp.FilterStatement()
# Get ad units by statement.
while True:
response = inventory_service.getAdUnitsByStatement(
statement.ToStatement())
if 'results' in response:
# Display results.
for ad_unit in response['results']:
print ('Ad unit with ID \'%s\' and name \'%s\' was found.'
% (ad_unit['id'], ad_unit['name']))
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
# networks = dfp_client.GetService('NetworkService').getAllNetworks()
# for network in networks:
# print ('Network with network code \'%s\' and display name \'%s\' was found.'
# % (network['networkCode'], network['displayName']))
if __name__ == '__main__':
main(SERVICE_ACCOUNT_EMAIL, KEY_FILE, APPLICATION_NAME)
嘿,我收到错误消息,oauth2.py
中的 googleads 存在错误
密钥文件应该以二进制模式打开
oauth2.py 中的第 208 行
打开(key_file)作为 f:
它应该与 open(key_file,'rb') as f:
我正在尝试使用 DFP 的服务帐户,但出现此错误
OpenSSL.crypto.Error: [('asn1 encoding routines', 'ASN1_D2I_READ_BIO', 'not enough data')]
我已经在 dfp 中添加了服务帐户并检查了已创建的服务帐户 email_id 但仍然无法解决问题
这是我的代码,有人可以帮我解决这个问题
from googleads import dfp
from googleads import oauth2
import logging
logging.basicConfig(filename='debug.log',level=logging.DEBUG)
# OAuth 2.0 credential information. In a real application, you'd probably be
# pulling these values from a credential storage.
SERVICE_ACCOUNT_EMAIL = '600632524044-6g7l2njp5g5ldd21j7eaolf1k15pdm1u@developer.gserviceaccount.com'
KEY_FILE = 'D:\DFP\GoogleDFP.p12'
# DFP API information.
APPLICATION_NAME = 'New Srevice Account'
def main(service_account_email, key_file, application_name):
# with open(key_file, 'rb') as f:
# private_key = f.read()
# f.close()
oauth2_client = oauth2.GoogleServiceAccountClient(
oauth2.GetAPIScope('dfp'), service_account_email, key_file)
client = dfp.DfpClient(oauth2_client, application_name)
inventory_service = client.GetService('InventoryService', version='v201505')
statement = dfp.FilterStatement()
# Get ad units by statement.
while True:
response = inventory_service.getAdUnitsByStatement(
statement.ToStatement())
if 'results' in response:
# Display results.
for ad_unit in response['results']:
print ('Ad unit with ID \'%s\' and name \'%s\' was found.'
% (ad_unit['id'], ad_unit['name']))
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
# networks = dfp_client.GetService('NetworkService').getAllNetworks()
# for network in networks:
# print ('Network with network code \'%s\' and display name \'%s\' was found.'
# % (network['networkCode'], network['displayName']))
if __name__ == '__main__':
main(SERVICE_ACCOUNT_EMAIL, KEY_FILE, APPLICATION_NAME)
嘿,我收到错误消息,oauth2.py
中的 googleads 存在错误密钥文件应该以二进制模式打开 oauth2.py 中的第 208 行 打开(key_file)作为 f:
它应该与 open(key_file,'rb') as f: