PHP Bing ads API:对cUrl请求的null响应 [英] PHP Bing ads API: null response on cUrl request
问题描述
您好,
我尝试在不使用SDK的PHP 5.4服务器上使用Bing广告API。
我成功获得了user_id,访问并刷新了来自https://login.live.com/oauth20_token.srf卷曲请求的令牌。
我现在正在尝试获取相关的广告系列,但即使使用错误的xml数据,我也会收到无响应的空响应。我尝试使用和不使用HTTP标头。我尝试了类似的东西甚至与其他服务(例如 CustomerManagementService)
但结果相同,所以我可能遗漏了一些东西。
网址: https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V12/CampaignManagementService.svc
标题:[" content-type:application / soap + xml; charset = utf8"," AuthenticationToken:$ this-> access_token"," DeveloperToken:$ this-> dev_token"]
< s:Envelope xmlns:i = \" http://www.w3.org/2001/XMLSchema-instance\"的xmlns:S =&\ QUOT; HTTP://schemas.xmlsoap.org/soap/envelope/\">
< s:Header xmlns = \" https://guideads.microsoft.com/CampaignManagement/v12\">
< Action mustUnderstand = \" 1 \"> GetCampaignsByAccountId< / Action>
< ApplicationToken i:nil = \" false \"> $ this-> application_id< / ApplicationToken>
< AuthenticationToken i:nil = \" false \"> $ this-> access_token< / AuthenticationToken>
< CustomerAccountId i:nil = \" false \"> $ this-> user_id< / CustomerAccountId>
< CustomerId i:nil = \" false \"> $ this-> customer_id< / CustomerId>
< DeveloperToken i:nil = \" false \"> $ this-> dev_token< / DeveloperToken>
<密码i:nil = \" false \"> HIDDEN< /密码>
< UserName i:nil = \" false \"> HIDDEN< / UserName>
< / s:标题>
< s:Body>
< GetCampaignsByAccountIdRequest xmlns = \" https://guideads.microsoft.com/CampaignManagement/v12\">
< AccountId> $ this-> account_id< / AccountId>
< CampaignType>搜索< / CampaignType>
< / GetCampaignsByAccountIdRequest>
< / s:Body>
< / s:信封>
我确实修剪了它。
access_token和user_id来自 https://login.live.com/oauth20_token.srf 响应。
来自Bing帐户页面的account_id和customer_id。
< p style ="">谢谢!
< blockquote>
请注意:
- 您应该将AccountId和CustomerAccountId设置为相同的值,即记录为
的仅数字ID
here 。 - 由于您使用的是access_token(通过AuthenticationToken标头),请将UserName和Password设置为nil或将其从标头中删除。
- 不需要设置ApplicationToken。它被忽略了。 (以任何方式与注册的应用程序ID /客户端ID无关)
您是否尝试过GetUser?要确认您的凭据是否正确(AuthenticationToken + DeveloperToken),我建议您通过客户管理服务从此示例SOAP请求开始:
<? xml version =" 1.0"编码= QUOT; UTF-8英寸;?>
< s:Envelope xmlns:s =" http://schemas.xmlsoap.org/soap/envelope/">
< s:标题>
< h:ApplicationToken i:nil =" true"的xmlns:H =" HTTPS://bingads.microsoft.com/Customer/v12"的xmlns:I =" HTTP://www.w3.org/2001/XMLSchema-instance" />
< h:AuthenticationToken xmlns:h =" https://guideads.microsoft.com/Customer/v12"> OAuthAccessTokenGoesHere< / h:AuthenticationToken>
< h:DeveloperToken xmlns:h =" https://guideads.microsoft.com/Customer/v12"> DeveloperTokenGoesHere< / h:DeveloperToken>
< h:密码i:nil =" true"的xmlns:H =" HTTPS://bingads.microsoft.com/Customer/v12"的xmlns:I =" HTTP://www.w3.org/2001/XMLSchema-instance" />
< h:UserName i:nil =" true"的xmlns:H =" HTTPS://bingads.microsoft.com/Customer/v12"的xmlns:I =" HTTP://www.w3.org/2001/XMLSchema-instance" />
< / s:标题>
< s:Body>
< GetUserRequest xmlns =" https://guideads.microsoft.com/Customer/v12">
< UserId i:nil =" true"的xmlns:I =" HTTP://www.w3.org/2001/XMLSchema-instance" />
< / GetUserRequest>
< / s:Body>
< / s:信封>
如果问题出现在curl设置本身你可能想要参考
客户端库代码。
致以最好的问候,
Eric
Hello,
I'm try to use Bing ads API on PHP 5.4 server without the SDK.
I successful gain user_id, access and refresh tokens from https://login.live.com/oauth20_token.srf curl request.
I'm trying now to get the associated campaigns but I receive always null response without errors even with a wrong xml data. I tried with and without HTTP headers. I tried something similar even with other service (eg CustomerManagementService) but same results so probably I'm missing something.
Url: https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V12/CampaignManagementService.svc
Headers: ["content-type: application/soap+xml; charset=utf8", "AuthenticationToken: $this->access_token", "DeveloperToken: $this->dev_token"]
<s:Envelope xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"> <s:Header xmlns=\"https://bingads.microsoft.com/CampaignManagement/v12\"> <Action mustUnderstand=\"1\">GetCampaignsByAccountId</Action> <ApplicationToken i:nil=\"false\">$this->application_id</ApplicationToken> <AuthenticationToken i:nil=\"false\">$this->access_token</AuthenticationToken> <CustomerAccountId i:nil=\"false\">$this->user_id</CustomerAccountId> <CustomerId i:nil=\"false\">$this->customer_id</CustomerId> <DeveloperToken i:nil=\"false\">$this->dev_token</DeveloperToken> <Password i:nil=\"false\">HIDDEN</Password> <UserName i:nil=\"false\">HIDDEN</UserName> </s:Header> <s:Body> <GetCampaignsByAccountIdRequest xmlns=\"https://bingads.microsoft.com/CampaignManagement/v12\"> <AccountId>$this->account_id</AccountId> <CampaignType>Search</CampaignType> </GetCampaignsByAccountIdRequest> </s:Body> </s:Envelope>
I did trimmed it.
access_token and user_id are got from the https://login.live.com/oauth20_token.srf response.
account_id and customer_id from the Bing account page.
Thank you!
Please note:
- You should set the AccountId and CustomerAccountId to the same value i.e., the numeric-only ID as documented here.
- Since you are using the access_token (via the AuthenticationToken header), please set UserName and Password nil or remove them from the headers completely.
- ApplicationToken does not need to be set. It is ignored. (Not related to the registered App ID / Client ID in any way)
Have you tried GetUser yet? To confirm whether your credentials are correct (AuthenticationToken + DeveloperToken), I suggest starting with this sample SOAP request via the Customer Management service:<?xml version="1.0" encoding="utf-8"?> <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <h:ApplicationToken i:nil="true" xmlns:h="https://bingads.microsoft.com/Customer/v12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /> <h:AuthenticationToken xmlns:h="https://bingads.microsoft.com/Customer/v12">OAuthAccessTokenGoesHere</h:AuthenticationToken> <h:DeveloperToken xmlns:h="https://bingads.microsoft.com/Customer/v12">DeveloperTokenGoesHere</h:DeveloperToken> <h:Password i:nil="true" xmlns:h="https://bingads.microsoft.com/Customer/v12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /> <h:UserName i:nil="true" xmlns:h="https://bingads.microsoft.com/Customer/v12" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /> </s:Header> <s:Body> <GetUserRequest xmlns="https://bingads.microsoft.com/Customer/v12"> <UserId i:nil="true" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /> </GetUserRequest> </s:Body> </s:Envelope>In case the issue is with the curl setup itself you might want to refer to the client library code.
Best regards,
Eric
这篇关于PHP Bing ads API:对cUrl请求的null响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!