更新PHP示例以考虑OAuth [英] Updating PHP Examples to Account for OAuth

查看:64
本文介绍了更新PHP示例以考虑OAuth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过大量的故障排除后,我无法启动并运行API。目前只是尝试成功完成任何脚本,所以我根据提供的PHP示例将下面的简单脚本放在一起。由于我收到
几个错误,指的是无效的客户端数据(下面的完整错误详细信息),我认为切换到OAuth会有所帮助,这可能会有一点点,但现在我遇到了"致命错误:致电一个成员函数GetService()在第80行的MY / URL / PATH.php
中的非对象上。我知道评论$ proxy会导致错误,但不知道要替换它。任何帮助将非常感激!注意,我已经用粗体显示第80行。





原始错误($ proxy未注释) out)


0无效的客户数据。检查SOAP故障详细信息以获取更多信息#0
MY / URL / PATH.php (80):SoapClient-> __ call('AddNegativeKeyw ...',Array)#1
MY / URL / PATH.php (80):SoapClient-> AddNegativeKeywordsToEntities(对象(BingAds\CampaignManagement\AddNegativeKeywordsToEntitiesRequest))#2
MY / URL / PATH.php (97):AddNegativeKeywordsToEntities(对象(BingAds \Proxy\ClientProxy),'mynegative')#3 {main}



当前错误(脚本低于+ OAuth)


致命错误:调用成员函数GetService( )在第80行的/ MY / URL / PATH.php 中的非对象上



<?php 
echo ini_set('display_errors','1');
//包括BingAds\v10命名空间类文件
//可从http://go.microsoft.com/fwlink/?LinkId=322147下载
require_once'bingads / CampaignManagementClasses .PHP';
require_once'bingads / ClientProxy.php';

//指定将使用的BingAds \CampaignManagement对象。
使用BingAds \CampaignManagement \ AddNegativeKeywordsToEntitiesRequest;
使用BingAds \ CampaignManagement \DeleteNegativeKeywordsFromEntitiesRequest;
使用BingAds \CampaignManagement\GetNegativeKeywordsByEntityIdsRequest;
使用BingAds\CampaignManagement\AddSharedEntityRequest;
使用BingAds \CampaignManagement \ GetSharedEntitiesByAccountIdRequest;
使用BingAds\CampaignManagement\UpdateSharedEntitiesRequest;
使用BingAds\CampaignManagement\DeleteSharedEntitiesRequest;
使用BingAds \CampaignManagement\AddListItemsToSharedListRequest;
使用BingAds \CampaignManagement\GetListItemsBySharedListRequest;
使用BingAds \CampaignManagement \DeleteListItemsFromSharedListRequest;
使用BingAds\CampaignManagement\SetSharedEntityAssociationsRequest;
使用BingAds \ CampaignManagement \ GetSharedEntityAssociationsByEntityIdsRequest;
使用BingAds \ CampaignManagement \ GetSharedEntityAssociationsBySharedEntityIdsRequest;
使用BingAds\CampaignManagement\DeleteSharedEntityAssociationsRequest;
使用BingAds\CampaignManagement\AddCampaignsRequest;
使用BingAds\CampaignManagement\DeleteCampaignsRequest;
使用BingAds \ CampaignManagement\Campaign;
使用BingAds \CampaignManagement \ EntityNegativeKeyword;
使用BingAds \ CampaignManagement \SharedEntityAssociation;
使用BingAds \CampaignManagement \ SharedEntity;
使用BingAds \CampaignManagement \ SharedList;
使用BingAds \CampaignManagement \SharedListItem;
使用BingAds\CampaignManagement\NegativeKeyword;
使用BingAds\CampaignManagement\NegativeKeywordList;
使用BingAds\CampaignManagement\BudgetLimitType;
使用BingAds\CampaignManagement\MatchType;

//指定将使用的BingAds \Proxy对象。
使用BingAds \Proxy \ClientProxy;

//禁用WSDL缓存。

ini_set(" soap.wsdl_cache_enabled"," 0");
ini_set(" soap.wsdl_cache_ttl"," 0");

//指定您的凭据。

$ authenticationToken =" XXXXXXXXXX" ;;
$ DeveloperToken =" XXXXXXXXXX"


 $ AccountId = XXXXXXXXX; 
$ CustomerId = XXXXXXXXX;
$ ApplicationToken =" XXXXXXXXX" ;;

//报告WSDL。
$ wsdl =" https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V10/CampaignManagementService.svc?singleWsdl" ;;

/ * try
{
$ proxy = ClientProxy :: ConstructWithAccountAndCustomerId($ wsdl,null,null,$ DeveloperToken,$ AccountId,$ CustomerId,null);}
catch(例外$ e)
{
if($ e-> getPrevious())
{
; //忽略我们已经捕获的错误异常。
}
else
{
print $ e-> getCode()。" " $ E->的getMessage()" \\\
\\\
英寸;
print $ e-> getTraceAsString()。" \ n\ n" ;;
}
} * /


函数AddNegativeKeywordsToEntities(
$ proxy,
$ entityNegativeKeywords)
{
尝试
{
$ request = new AddNegativeKeywordsToEntitiesRequest();
$ request-> EntityNegativeKeywords = $ entityNegativeKeywords;
返回$ proxy-> GetService() - > AddNegativeKeywordsToEntities($ request);
}
catch(例外$ e)
{
if($ e-> getPrevious())
{
; //忽略我们已经捕获的错误异常。
}
else
{
print $ e-> getCode()。" " $ E->的getMessage()" \\\
\\\
英寸;
print $ e-> getTraceAsString()。" \ n\ n" ;;
}
}
}
尝试
{
AddNegativeKeywordsToEntities($ proxy,'mynegative');
}
catch(例外$ e)
{
if($ e-> getPrevious())
{
; //忽略我们已经捕获的错误异常。
}
else
{
print $ e-> getCode()。" " $ E->的getMessage()" \\\
\\\
英寸;
print $ e-> getTraceAsString()。" \ n\ n" ;;
}
}
?>




在此先感谢。


解决方案

您可以保留代理并使用OAuth。这是
中定义的函数定义
ClientProxy.php

公共静态函数ConstructWithAccountId(


wsdl,

用户名,

After a good amount of troubleshooting I haven't been able to get up and running with the API. Currently just trying to complete any script successfully, so I put together the simple script below based on the PHP examples provided. Since I was receiving several errors referring to invalid client data (full error details below) I thought switching to OAuth would help, which it may have slightly, but now I'm running into "Fatal error: Call to a member function GetService() on a non-object in MY/URL/PATH.php on line 80". I know commenting out $proxy is going to lead to an error, but not sure what to replace it with. Any help would be much appreciated! Note, I've bolded line 80.


Original Error (with $proxy not commented out)

0 Invalid client data. Check the SOAP fault details for more information #0 MY/URL/PATH.php(80): SoapClient->__call('AddNegativeKeyw...', Array) #1 MY/URL/PATH.php(80): SoapClient->AddNegativeKeywordsToEntities(Object(BingAds\CampaignManagement\AddNegativeKeywordsToEntitiesRequest)) #2 MY/URL/PATH.php(97): AddNegativeKeywordsToEntities(Object(BingAds\Proxy\ClientProxy), 'mynegative') #3 {main}

Current Error (with script below + OAuth)

Fatal error: Call to a member function GetService() on a non-object in /MY/URL/PATH.php on line 80

<?php
echo ini_set('display_errors', '1');
// Include the BingAds\v10 namespaced class file available
// for download at http://go.microsoft.com/fwlink/?LinkId=322147
require_once 'bingads/CampaignManagementClasses.php';
require_once 'bingads/ClientProxy.php'; 

// Specify the BingAds\CampaignManagement objects that will be used.
use BingAds\CampaignManagement\AddNegativeKeywordsToEntitiesRequest;
use BingAds\CampaignManagement\DeleteNegativeKeywordsFromEntitiesRequest;
use BingAds\CampaignManagement\GetNegativeKeywordsByEntityIdsRequest;
use BingAds\CampaignManagement\AddSharedEntityRequest;
use BingAds\CampaignManagement\GetSharedEntitiesByAccountIdRequest;
use BingAds\CampaignManagement\UpdateSharedEntitiesRequest;
use BingAds\CampaignManagement\DeleteSharedEntitiesRequest;
use BingAds\CampaignManagement\AddListItemsToSharedListRequest;
use BingAds\CampaignManagement\GetListItemsBySharedListRequest;
use BingAds\CampaignManagement\DeleteListItemsFromSharedListRequest;
use BingAds\CampaignManagement\SetSharedEntityAssociationsRequest;
use BingAds\CampaignManagement\GetSharedEntityAssociationsByEntityIdsRequest;
use BingAds\CampaignManagement\GetSharedEntityAssociationsBySharedEntityIdsRequest;
use BingAds\CampaignManagement\DeleteSharedEntityAssociationsRequest;
use BingAds\CampaignManagement\AddCampaignsRequest;
use BingAds\CampaignManagement\DeleteCampaignsRequest;
use BingAds\CampaignManagement\Campaign;
use BingAds\CampaignManagement\EntityNegativeKeyword;
use BingAds\CampaignManagement\SharedEntityAssociation;
use BingAds\CampaignManagement\SharedEntity;
use BingAds\CampaignManagement\SharedList;
use BingAds\CampaignManagement\SharedListItem;
use BingAds\CampaignManagement\NegativeKeyword;
use BingAds\CampaignManagement\NegativeKeywordList;
use BingAds\CampaignManagement\BudgetLimitType;
use BingAds\CampaignManagement\MatchType;

// Specify the BingAds\Proxy objects that will be used.
use BingAds\Proxy\ClientProxy;

// Disable WSDL caching.

ini_set("soap.wsdl_cache_enabled", "0");
ini_set("soap.wsdl_cache_ttl", "0");

// Specify your credentials.

$authenticationToken = "XXXXXXXXXX";
$DeveloperToken = "XXXXXXXXXX"

$AccountId = XXXXXXXXX;
$CustomerId = XXXXXXXXX;
$ApplicationToken = "XXXXXXXXX";

// Reporting WSDL.
$wsdl = "https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V10/CampaignManagementService.svc?singleWsdl";

/*try
{        
   $proxy = ClientProxy::ConstructWithAccountAndCustomerId($wsdl, null, null, $DeveloperToken, $AccountId, $CustomerId, null);}	
 catch (Exception $e)
{
    if ($e->getPrevious())
    {
        ; // Ignore fault exceptions that we already caught.
    }
    else
    {
        print $e->getCode()." ".$e->getMessage()."\n\n";
        print $e->getTraceAsString()."\n\n";
    }
}*/


function AddNegativeKeywordsToEntities(
         $proxy,
         $entityNegativeKeywords)
{
try 
{
    $request = new AddNegativeKeywordsToEntitiesRequest();
    $request->EntityNegativeKeywords = $entityNegativeKeywords;
    return $proxy->GetService()->AddNegativeKeywordsToEntities($request);
}
 catch (Exception $e)
{
    if ($e->getPrevious())
    {
        ; // Ignore fault exceptions that we already caught.
    }
    else
    {
        print $e->getCode()." ".$e->getMessage()."\n\n";
        print $e->getTraceAsString()."\n\n";
    }
}
}
try 
{
 AddNegativeKeywordsToEntities($proxy, 'mynegative');
    }
 catch (Exception $e)
{
    if ($e->getPrevious())
    {
        ; // Ignore fault exceptions that we already caught.
    }
    else
    {
        print $e->getCode()." ".$e->getMessage()."\n\n";
        print $e->getTraceAsString()."\n\n";
    }
}
?>


Thanks in advance.

解决方案

You can keep the proxy and use OAuth. Here is the function definition defined in ClientProxy.php:

public static function ConstructWithAccountId(


wsdl,


username,


这篇关于更新PHP示例以考虑OAuth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆