尝试使用PHP SDK更新Bing Ads Campaign的CampaignCriterions时,无法创建抽象类错误

时间:2017-09-25 19:07:11

标签: php bing-ads-api

尝试使用适用于Bing Ads Api的PHP SDK为CampaignCriterions更新Campaign时出现以下错误。

在搜索解决方案时,我遇到this code example并尝试使用SoapVar对对象进行编码。我仍然得到同样的错误。也许,我在这里遗漏了一些东西。对此的任何帮助都会很棒。

代码

$criterion = new CampaignCriterion();
$criterion->CampaignId = $campaignCriterion->CampaignId;
$criterion->Criterion = $radiusCriterion;
$criterion->Id = $campaignCriterion->Id;
$criterion->Type = CampaignCriterionType::Radius;

$request = new UpdateCampaignCriterionsRequest();
$request->CampaignCriterions = [$criterion];

try {
    return $campaignManagementServiceProxy->GetService()->UpdateCampaignCriterions($request);   
} catch (SoapFault $se) {
    print_r($se);
}

异常

[ExceptionDetail] => stdClass Object
(
    [HelpLink] => 
    [InnerException] => 
    [Message] => Cannot create an abstract class.
    [StackTrace] =>    
        at System.Runtime.Serialization.FormatterServices.nativeGetUninitializedObject(RuntimeType type)
        at ReadCampaignCriterionFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] )
        at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
        at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
        at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns)
        at ReadArrayOfCampaignCriterionFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString , XmlDictionaryString , CollectionDataContract )
        at System.Runtime.Serialization.CollectionDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
        at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
        at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
        at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
        at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
        at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)
        at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.PartInfo.ReadObject(XmlDictionaryReader reader, XmlObjectSerializer serializer)
        at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
        at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, Object[] parameters, Boolean isRequest)
        at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
        at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
        at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
        at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)
        at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
        at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
        at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
        at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
    [Type] => System.MemberAccessException
)

更新09/26: 可出价的广告系列标准 添加了BiddableCampaignCriterion,并从CampaignCriterion派生属性,CampaignCriterion现在是一个抽象基类。您必须在添加,获取和更新广告系列标准操作时使用BiddableCampaignCriterion而不是CampaignCriterion。

1 个答案:

答案 0 :(得分:0)

  1. 只要CriterionCriterionBid未使用SoapVar加密,就会发生这种情况。
  2. 最终CampaignCriterion应加密为BiddableCampaignCriterion
  3. 您的最终代码应如下所示(旧代码已注释掉):

    $criterion = new CampaignCriterion();
    // $criterion->CampaignId = $campaignCriterion->CampaignId;
    $criterion = $campaignCriterion;
    
    // $criterion->Criterion = $radiusCriterion;
    $criterion->Criterion = new SoapVar($radiusCriterion, SOAP_ENC_OBJECT, 'RadiusCriterion', $campaignManagementServiceProxy->GetNamespace());
    
    $criterion->Id = $campaignCriterion->Id;
    // $criterion->Type = CampaignCriterionType::Radius; 
    $criterion->CriterionBid = new SoapVar($campaignCriterion->CriterionBid, SOAP_ENC_OBJECT, 'BidMultiplier', $campaignManagementServiceProxy->GetNamespace());
    
    $request = new UpdateCampaignCriterionsRequest();
    // $request->CampaignCriterions = [$criterion];
    $request->CampaignCriterions = [new SoapVar($criterion, SOAP_ENC_OBJECT, 'BiddableCampaignCriterion', $campaignManagementServiceProxy->GetNamespace());];
    
    try {
        return $campaignManagementServiceProxy->GetService()->UpdateCampaignCriterions($request);   
    } catch (SoapFault $se) {
        print_r($se);
    }
    

    <强>参考文献:   - https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-radiuscriterion.aspx   - https://msdn.microsoft.com/en-us/library/mt807658%28v=msads.110%29.aspx?f=255&MSPPError=-2147217396