本文将分享通过FuelSDK-Python访问SalesForceMarketingCloudAPI的详细内容,并且还将对python访问ftp服务器进行详尽解释,此外,我们还将为大家带来关于Face
本文将分享通过 FuelSDK-Python 访问 SalesForce Marketing Cloud API的详细内容,并且还将对python访问ftp服务器进行详尽解释,此外,我们还将为大家带来关于Facebook Marketing API Ads Insights to CSV in Python、Marketing Cloud API消费entity unsupported format错误消息的处理、Marketing Cloud contact 的 API 介绍、Marketing Cloud contact主数据的csv导入的相关知识,希望对你有所帮助。
本文目录一览:- 通过 FuelSDK-Python 访问 SalesForce Marketing Cloud API(python访问ftp服务器)
- Facebook Marketing API Ads Insights to CSV in Python
- Marketing Cloud API消费entity unsupported format错误消息的处理
- Marketing Cloud contact 的 API 介绍
- Marketing Cloud contact主数据的csv导入
通过 FuelSDK-Python 访问 SalesForce Marketing Cloud API(python访问ftp服务器)
如何解决通过 FuelSDK-Python 访问 SalesForce Marketing Cloud API
我正在尝试从我们的 SalesForce Marketing Cloud 实例中验证和查询数据,我希望通过 Python 脚本中的 API 执行此操作。
我通读了 SalesForce 开发人员文档,他们指出我使用 FuelSDK-Python 作为连接和查询的主要方式。
我正在尝试连接,但一直遇到相同的错误。有人告诉我,我只需要 4 个输入就可以完成这项工作 ''client_id'' 、 ''client_secret'' 、''baseapiuri'' 和 SF MC 平台内的 ''accountID'',我已经将这些输入到下面的脚本中(真实 ID / 秘密未显示):
import pandas as pd
import numpy as np
import FuelSDK
sf_cp_client_id = ''sh7uj5u78myclientidcrvvcyx''
sf_cp_client_secret = ''w6D4NmysecretMR90Aak''
rest_base_URI = ''https://mc-97-bn31-85yc47k-pD5rV0vp1.rest.marketingcloudapis.com/''
sf_cp_client = FuelSDK.ET_Client(False,False,{''clientid'': sf_cp_client_id,''clientsecret'': sf_cp_client_secret,''baseapiurl'': rest_base_URI,''accountId'': 515111362,# specific MID that I''m using within SF MC
})
# Create an instance of the object type we want to work with:
list = FuelSDK.ET_List()
# Associate the ET_Client to the object using the auth_stub property:
list.auth_stub = sf_cp_client
# Utilize one of the ET_List methods:
response = list.get()
# Print out the results for viewing
print ("PostStatus" + str(response.status))
以下是我得到的以下异常
c:\\Users\\Jason Weir\\Documents\\GitHub\\boomerang\\cloudfunctions\\digital_data_inventory_v2\\main2.py in
7 rest_base_URI = ''https://mc-97-bn31-85yc47k-pD5rV0vp1.rest.marketingcloudapis.com/''
8
----> 9 sf_cp_client = FuelSDK.ET_Client(False,10 {''clientid'': sf_cp_client_id,11 ''clientsecret'': sf_cp_client_secret,C:\\Anaconda3\\lib\\site-packages\\FuelSDK\\client.py in __init__(self,get_server_wsdl,debug,params,tokenResponse)
54 logging.getLogger(''suds'').setLevel(logging.INFO)
55
---> 56 self.configure_client(get_server_wsdl,tokenResponse)
57
58 def configure_client(self,tokenResponse):
C:\\Anaconda3\\lib\\site-packages\\FuelSDK\\client.py in configure_client(self,tokenResponse)
205 pass
206 else:
--> 207 self.refresh_token()
208
209
C:\\Anaconda3\\lib\\site-packages\\FuelSDK\\client.py in refresh_token(self,force_refresh)
295
296 if ''accesstoken'' not in tokenResponse:
--> 297 raise Exception(''Unable to validate App Keys(ClientID/ClientSecret) provided: '' + repr(r.json()))
298
299 self.authToken = tokenResponse[''accesstoken'']
Exception: Unable to validate App Keys(ClientID/ClientSecret) provided: {''message'': ''Unauthorized'',''errorcode'': 1,''documentation'': ''''}
欢迎任何关于我如何修复的建议。
Facebook Marketing API Ads Insights to CSV in Python
如何解决Facebook Marketing API Ads Insights to CSV in Python
如何将 Facebook Marketing API 广告洞察的响应导出为 CSV。
下面是我的代码和它的响应。
from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
app_id = ''xxxxxxxxxxxxx''
app_secret = ''xxxxxxxxxxxxx''
access_token = ''xxxxxxxxx''
FacebookAdsApi.init(app_id,app_secret,access_token)
params = {''time_range'': {''since'': ''2020-01-01'',''until'': ''2020-12-25''},''time_increment'':1,''level'': ''adset'',''sort'': [''spend_descending''],''export_format'':''csv''}
fields = [''account_name'',''campaign_name'',''campaign_id'',''adset_name'',''adset_id'',''impressions'',''clicks'',''cpm'',''spend'',''ctr'']
insights = AdAccount(''act_332828570147114'').get_insights(params=params,fields=fields)
print(insights)
回复是
[<AdsInsights> {
"account_name": "xxx","adset_id": "xxx","adset_name": "xxx","campaign_id": "xxx","campaign_name": "xxx","clicks": "xxx","cpm": "xxx","ctr": "xxx","date_start": "xxx","date_stop": "xxx","impressions": "xxx","spend": "xxx"
},<AdsInsights> {
"account_name": "xxx","spend": "xxx"
}]
我们如何将此响应导出为 CSV 格式?任何建议将不胜感激。
解决方法
from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
app_id = ''xxxxxxxxxxxxx''
app_secret = ''xxxxxxxxxxxxx''
access_token = ''xxxxxxxxx''
FacebookAdsApi.init(app_id,app_secret,access_token)
params = {''time_range'': {''since'': ''2020-01-01'',''until'': ''2020-12-25''},''time_increment'':1,''level'': ''adset'',''sort'': [''spend_descending''],''export_format'':''csv''}
fields = [''account_name'',''campaign_name'',''campaign_id'',''adset_name'',''adset_id'',''impressions'',''clicks'',''cpm'',''spend'',''ctr'']
insights = list(AdAccount(''act_332828570147114'').get_insights(params=params,fields=fields))
import pandas as pd
df=pd.DataFrame(columns=fields)
for field in fields:
df["{}".format(field)]=[x[''{}''.format(field)] for x in insights]
df.to_csv("insights.csv",index=False)
与作为字典的 adinsights 对象交互并将它们添加到数据框,然后保存为 csv!
Marketing Cloud API消费entity unsupported format错误消息的处理
在消费SAP Marketing Cloud API时,遇到如下错误:

解决方案是在发起http请求的头部添加content-type字段,类型为multipart/mixed:

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
本文同步分享在 博客“汪子熙”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
Marketing Cloud contact 的 API 介绍
下图的 contact 列表是 Marketing Cloud 调用后台 odata 服务后显示的:
URL:https://jerry.gcdemo.hybris.com/sap/opu/odata/sap/CUAN_CONTACT_SRV/$batch?sap-client=100
http 请求的正文:
–batch_c914-a60c-1877
Content-Type: application/http
Content-Transfer-Encoding: binary
GET InteractionContacts?sap-client=100&KaTeX parse error: Expected ''EOF'', got ''&'' at position 7: skip=0&̲top=45& s e l e c t = I m a g e U R L select=ImageURL%2cName%2cContactLevelName%2cCountryName%2cCity%2cEMailAddress%2cPhoneNumber%2cMobilePhoneNumber%2cCorporateAccountName%2cInteractionContactUUID%2cRelationship%2cType& select=ImageURLinlinecount=allpages HTTP/1.1
sap-cancel-on-close: true
Cache-Control: max-age=360
sap-contextid-accept: header
Accept: application/json
Accept-Language: en
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
–batch_c914-a60c-1877–
http 响应:
{“d”:{"__count":“1218374”,“results”:[{"__metadata":{“id”:“https://diablo.gcdemo.hybris.com/sap/opu/odata/sap/CUAN_CONTACT_SRV/InteractionContacts(‘00163E1B0A701EE6939977B1F8726D4C’)",“uri”:“https://diablo.gcdemo.hybris.com/sap/opu/odata/sap/CUAN_CONTACT_SRV/InteractionContacts(‘00163E1B0A701EE6939977B1F8726D4C’)”,“type”:“CUAN_CONTACT_SRV.InteractionContact”},“InteractionContactUUID”:“00163E1B0A701EE6939977B1F8726D4C”,“City”:“Newman”,“ContactLevelName”:“Self-Identified”,“CorporateAccountName”:"",“CountryName”:“USA”,“EMailAddress”:“0200205812_agatha.steward-90@outlook.com”,“ImageURL”:"",“MobilePhoneNumber”:"",“Name”:"Agatha Steward”,“PhoneNumber”:"",“Relationship”:1,“Type”:“01”},{"__metadata":{“id”:“https://diablo.gcdemo.hybris.com/sap/opu/odata/sap/CUAN_CONTACT_SRV/InteractionContacts(‘00163E1B0A701ED6939FBB838E1E803A’)",“uri”:“https://diablo.gcdemo.hybris.com/sap/opu/odata/sap/CUAN_CONTACT_SRV/InteractionContacts(‘00163E1B0A701ED6939FBB838E1E803A’)”,“type”:“CUAN_CONTACT_SRV.InteractionContact”},“InteractionContactUUID”:“00163E1B0A701ED6939FBB838E1E803A”,“City”:"",“ContactLevelName”:“Self-Identified”,“CorporateAccountName”:"",“CountryName”:“USA”,“EMailAddress”:“antonioifernandez@einrot.com”,“ImageURL”:"",“MobilePhoneNumber”:"",“Name”:"Antonio Fernandez”,“PhoneNumber”:"",“Relationship”:0,“Type”:“01”},{"__metadata":
本文同步分享在 博客 “汪子熙”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与 “OSC 源创计划”,欢迎正在阅读的你也加入,一起分享。
Marketing Cloud contact主数据的csv导入
使用这个mock数据生成器网站https://www.mockaroo.com/b6790790,创建一个基于Marketing Cloud contact schema的csv文件。
如果偷懒的话,每个contact字段的值都可以选择随机生成。点Download Data下载到本地。
打开csv文件之后,还可以用文本编辑器对值进行微调。
进入Marketing Cloud,点Import进行导入:
在business administration这个catalog里的import monitor对导入过程进行监控:
导入成功:
导入的数据可以在Marketing Cloud里使用了:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
今天关于通过 FuelSDK-Python 访问 SalesForce Marketing Cloud API和python访问ftp服务器的介绍到此结束,谢谢您的阅读,有关Facebook Marketing API Ads Insights to CSV in Python、Marketing Cloud API消费entity unsupported format错误消息的处理、Marketing Cloud contact 的 API 介绍、Marketing Cloud contact主数据的csv导入等更多相关知识的信息可以在本站进行查询。
本文标签: