本文介绍了凭据错误无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我使用了以下代码&得到错误 AdApiError代码:105错误代码:InvalidCredentials消息:认证失败。提供的凭据无效或帐户处于非活动状态。但我的所有凭据都正确...  <?php //包括可用的Bing Ads命名空间类文件  //可从http:/下载/go.microsoft.com/fwlink/?LinkId=322147  包含'bingads\BulkClasses.php';  包括'bingads \ClientProxy.php ';    //指定将要使用的BingAds \Bulk对象。  使用BingAds \ Bulk \DownloadCampaignsByCampaignIdsRequest;  使用BingAds \Bulk \BulkDownloadEntity;  使用BingAds \Bulk \ DataScope;  使用BingAds \Bulk \ CampaignScope;  使用BingAds \Bulk \ GetDetailedBulkDownloadStatusRequest;  使用BingAds \Bulk \DownloadStatus;   使用BingAds \Bulk \ DownloadFileType;  使用BingAds \Bulk \ PerformanceStatsDat eRange;  使用BingAds \Bulk \ CustomCateDateRangeEnd;  使用BingAds \Bulk \ CustomCateDanRangeStart;  使用BingAds \Bulk \ Date;  使用BingAds \Bulk \ GetBulkUploadUrlRequest;  使用BingAds \Bulk \ ResponseMode;  使用BingAds \Bulk \ GetDetailedBulkUploadStatusRequest;    //指定将使用的BingAds \Proxy对象。   使用BingAds \Proxy \ClientProxy;    //禁用WSDL缓存。    ini_set(" soap.wsdl_cache_enabled"," 0");  ini_set(" soap.wsdl_cache_ttl"," 0 QUOT);&NBSP; $ //指定您的凭证。 $ UserName =" ******英寸;   //我的bing广告用户名 $密码=" ******" ;;   //我的bing广告密码 $ DeveloperToken =" *******" ;; //来自开发者页面的令牌 $ AccountId = *****;   //在bing结算页面中, $ CustomerId = *****;   //在bing结算页面中$ //批量WSDL    $ wsdl =" https://api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V9/BulkService.svc?singleWsdl";      //批量文件的完整路径。    $ BulkFilePath =" c:\\bing\\" ;;    //完整路径以前提取的批量文件。  //此文件用于访问上次同步时间。    $ ExtractedFilePath =" c:\\bulk \\extracted\\accounts.csv";    //完整路径上传结果文件。    $ UploadResultFilePath =" c:\\bulk \\uploadresults.zip";    //指定批量文件格式。    $ Fi leFormat = DownloadFileType :: Csv;      //确认下载文件夹存在;否则,退出。    $ length = strrpos($ BulkFilePath,'\\');  $ folder = substr($ BulkFilePath,0,$ length);    if(!is_dir($ folder))  {    &NBSP; printf("输出文件夹,%s,不存在。\ n确保存在&。      "文件夹,然后重试。" ;,$ folder);    &NBSP;返回;  }    试试  {    &NBSP; $ proxy = ClientProxy :: ConstructWithAccountAndCustomerId($ wsdl,$ UserName,$ Password,$ DeveloperToken,$ AccountId,$ CustomerId,null);      ; &NBSP; //使用批量服务下载批量文件。    &NBSP;     &NBSP; //广告系列必须全部属于同一帐户。    &NBSP;     &NBSP; $ campaigns = array();    &NBSP;     &NBSP; foreach($ CampaignIds为$ id)    &NBSP; {    &NBSP; &NBSP; &NBSP; $ scope = new CampaignScope();    &NBSP; &NBSP; &NBSP; $ scope-> CampaignId = $ id;    &NBSP; &NBSP; &NBSP; $ scope-> ParentAccountId = $ AccountId;    &NBSP; &NBSP; &NBSP; $ campaign [] = $ scope;    &NBSP; }    &NBSP;     &NBSP; $ dataScope = DataScope :: EntityData;    &NBSP;     &NBSP; $ entities = array(       BulkDownloadEntity :: Ads,       BulkDownloadEntity :: AdGroups ,       BulkDownloadEntity :: Campaigns,       BulkDownloadEntity :: Keywords      );      &NBSP; $ formatVersion =" 2.0";    &NBSP;     &NBSP; $ lastSyncTimeInUTC = GetLastSyncTime($ ExtractedFilePath);    &NBSP;     &NBSP; //如果lastSyncTime为null,则您可以包含非空日期范围,并且数据范围包括    &NBSP; // EntityPerformanceData,BidSuggestionsData或QualityScoreData。    &NBSP;     &NBSP; / *    &NBSP; $ performanceStatsDateRange = new PerformanceStatsDateRange();    &NBSP; $ performanceStatsDateRange-> CustomDateRangeEnd = new Date();    &NBSP; $ performanceStatsDateRange-> CustomDateRangeEnd-> Day = 15;    &NBSP; $ performanceStatsDateRange-> CustomDateRangeEnd-> Month = 9;    &NBSP; $ performanceStatsDateRange-> CustomDateRangeEnd-> Year = 2013;    &NBSP; $ performanceStatsDateRange-> CustomDateRangeStart = new Date();    &NBSP; $ performanceStatsDateRange-> CustomDateRangeStart-> Day = 15;    &NBSP; $ performanceStatsDateRange-> CustomDateRangeStart-> Month = 9;    &NBSP; $ performanceStatsDateRange-> CustomDateRangeStart-> Year = 2013;    &NBSP; * /    &NBSP;     &NBSP; // GetDownloadRequestId帮助方法调用相应的Bing Ads服务操作    &NBSP; //请求下载标识符。    &NBSP;     &NBSP; $ downloadRequestId = GetDownloadRequestId(         $ proxy,          $ campaign, &       $ dataScope,          $ FileFormat,         $ entities,            $ formatVersion,         $ lastSyncTimeInUTC,          null        );    &NBSP;     &NBSP; $ waitTime = 5 * 1;     &NBSP; &NBSP; &NBSP;     &NBSP; if($ downloadRequestId!= null)    &NBSP; {    &NBSP; &NBSP; &NBSP; printf("下载请求ID:%s \ n",$ downloadRequestId);      &NBSP; &NBSP; &NBSP; $ downloadSuccess = false;    &NBSP;     &NBSP; &NBSP; &NBSP; //此示例每30秒轮询一次,最多5分钟。    &NBSP; &NBSP; &NBSP; //在制作中,您可以每隔1到2分钟轮询状态,最多一小时。    &NBSP; &NBSP; &NBSP; //如果呼叫成功,请停止轮询。如果是通话或者是&bbsp   &NBSP; &NBSP; &NBSP; //下载失败,通话会引发错误。    &NBSP;     &NBSP; &NBSP; &NBSP; for($ i = 0; $ i< 10; $ i ++)    &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;睡觉($ waitTime);    &NBSP;     &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; // GetDownloadRequestStatus帮助方法调用相应的Bing Ads服务操作    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //获取下载状态。    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;     &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ downloadRequestStatus = GetDownloadRequestStatus(           $ proxy,            $ downloadRequestId          );    ; &NBSP;     &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(($ downloadRequestStatus!= null)&&($ downloadRequestStatus ==" Completed"))    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ downloadSuccess = true;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }    &NBSP; &NBSP; &NBSP; }      &NBSP; &NBSP; &NBSP; if($ downloadSuccess)    &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ downloadUrl = GetDownloadUrl(             $ proxy,              $ downloadRequestId            ) ;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; printf("从%s。\ n \ nn"下载,$ downloadUrl);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DownloadFile($ downloadUrl,$ BulkFilePath);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; printf("下载文件已写入%s。\ n",$ BulkFilePath);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;     &NBSP; &NBSP; &NBSP; }    &NBSP; &NBSP; &NBSP;否则//待定    &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; printf("请求的时间比预期的要长。\ n"。             "保存下载请求ID(%s),稍后再试。\ n",             $ downloadRequestId);    &NBSP; &NBSP; &NBSP; }    &NBSP; }  &NBSP; &NBSP; &NBSP;   }  catch(SoapFault $ e)  {    &NBSP; //输出最后一个请求/响应。    &NBSP;     &NBSP;打印"\\\最后的SOAP请求/响应:\ n";    &NBSP; print $ proxy-> GetWsdl()。 " \ n";    &NBSP; print $ proxy-> GetService() - > __ getLastRequest()。" \ n";    &NBSP; print $ proxy-> GetService() - > __ getLastResponse()。" \ n";    &NBSP;     &NBSP; //批量服务操作可以抛出AdApiFaultDetail。    &NBSP; if(isset($ e-> detail-> AdApiFaultDetail))    &NBSP; {    &NBSP; &NBSP; &NBSP; //记录此错误。      &NBSP; &NBSP; &NBSP;打印"操作失败并出现以下错误:\ n";      &NBSP; &NBSP; &NBSP; $ errors = is_array($ e-> detail-> AdApiFaultDetail->错误 - > AdApiError)    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ? $ e-> detail-> AdApiFaultDetail->错误 - > AdApiError    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; :array('AdApiError'=> $ e-> detail-> AdApiFaultDetail-> Errors-> AdApiError);      ; &NBSP; &NBSP; &NBSP; //如果AdApiError数组不为null,则以下是可能找到的错误代码的示例。    &NBSP; &NBSP; &NBSP; foreach($错误为$ error)    &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;打印"AdApiError \ n";    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; printf("Code:%d\\\Error Code:%s \ nMessage:%s \ nn",$ error-> Code,$ error-> ErrorCode,$ error-> Message);      &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;开关($ error->代码)    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例0:    // InternalError    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例105:  // InvalidCredentials    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;默认值:    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;打印"请参阅MSDN文档,了解有关上述错误代码输出的详细信息。\ n";    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }    &NBSP; &NBSP; &NBSP; }    &NBSP; }      &NBSP; //批量服务操作可以抛出ApiFaultDetail。    &NBSP; elseif(isset($ e-> detail-> ApiFaultDetail))    &NBSP; {    &NBSP; &NBSP; &NBSP; //记录此错误。      &NBSP; &NBSP; &NBSP;打印"操作失败并出现以下错误:\ n";      &NBSP; &NBSP; &NBSP; //如果BatchError数组不为null,则以下是可能找到的错误代码的示例。    &NBSP; &NBSP; &NBSP; if(!empty($ e-> detail-> ApiFaultDetail-> BatchErrors))    &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ errors = is_array($ e-> detail-> ApiFaultDetail-> BatchErrors-> BatchError)    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ? $ e-> detail-> ApiFaultDetail-> BatchErrors-> BatchError    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; :array('BatchError'=> $ e-> detail-> ApiFaultDetail-> BatchErrors-> BatchError);      ; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; foreach($错误为$ error)    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; printf("IndexError at index:%d \ n",$ error-> Index);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; printf("Code:%d\\\Error Code:%s \ nMessage:%s \ nn",$ error-> Code,$ error-> ErrorCode,$ error-> Message);      &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;开关($ error->代码)    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例0:  &NBSP; // InternalError    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;默认值:    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;打印"请参阅MSDN文档,了解有关上述错误代码输出的详细信息。\ n";    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }    &NBSP; &NBSP; &NBSP; }      &NBSP; &NBSP; &NBSP; //如果OperationError数组不为null,则以下是可能找到的错误代码的示例。    &NBSP; &NBSP; &NBSP; if(!empty($ e-> detail-> ApiFaultDetail-> OperationErrors))    &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ errors = is_array($ e-> detail-> ApiFaultDetail-> OperationErrors-> OperationError)    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ? $ e-> detail-> ApiFaultDetail-> OperationErrors-> OperationError    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; :array('OperationError'=> $ e-> detail-> ApiFaultDetail-> OperationErrors-> OperationError);      ; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; foreach($错误为$ error)    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;打印"OperationError \ n";    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; printf("Code:%d\\\Error Code:%s \ nMessage:%s \ nn",$ error-> Code,$ error-> ErrorCode,$ error-> Message);      &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;开关($ error->代码)    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例0:  &NBSP; // InternalError    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;案例106:  // UserIsNotAuthorized    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;默认值:    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;打印"请参阅MSDN文档,了解有关上述错误代码输出的详细信息。\ n";    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;休息;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }    &NBSP; &NBSP; &NBSP; }    &NBSP; }  }  catch(例外$ e)  {    ; &NBSP; if($ e-> getPrevious())    &NBSP; {    &NBSP; &NBSP; &NBSP; ; //忽略我们已经捕获的错误异常。    &NBSP; }    &NBSP;否则    &NBSP; {    &NBSP; &NBSP; &NBSP; print $ e-> getCode()。" "。$ e-> getMessage()。" \ n \ n";    &NBSP; &NBSP; &NBSP; print $ e-> getTraceAsString()。" \ n\ n";    &NBSP; }  }    // GetDownloadRequestId帮助方法调用DownloadCampaignsByCampaignIds服务操作  //请求下载标识符。    &NBSP; &NBSP; &NBSP;   函数GetDownloadRequestId($ proxy,$ campaigns,$ dataScope,$ downloadFileType,&     $ entities,$ formatVersion,$ lastSyncTimeInUTC,$ performanceStatsDateRange)  {    &NBSP; //设置请求信息。    &NBSP; $ request = new DownloadCampaignsByCampaignIdsRequest();    &NBSP; $ request->广告系列= $ campaign;    &NBSP; $ request-> DataScope = $ dataScope;    &NBSP; $ request-> DownloadFileType = $ downloadFileType;    &NBSP; $ request->实体= $实体;    &NBSP; $ request-> FormatVersion = $ formatVersion;    &NBSP; $ request-> LastSyncTimeInUTC = $ lastSyncTimeInUTC;    &NBSP; $ request-> PerformanceStatsDateRange = $ performanceStatsDateRange;    &NBSP; &NBSP; &NBSP;     &NBSP;返回$ proxy-> GetService() - > DownloadCampaignsByCampaignIds($ request) - > DownloadRequestId;  }      // GetDownloadRequestStatus帮助方法调用GetDetailedBulkDownloadStatus服务操作  //以获取下载请求状态。    函数GetDownloadRequestStatus($ proxy,$ requestId)  {    &NBSP; $ request = new GetDetailedBulkDownloadStatusRequest();    &NBSP; $ request-> RequestId = $ requestId;      &NBSP;返回$ proxy-> GetService() - > GetDetailedBulkDownloadStatus($ request) - > RequestStatus;  }    // GetDownloadUrl帮助方法调用GetDetailedBulkDownloadStatus服务操作  //获取下载URL。    函数GetDownloadUrl($ proxy,$ requestId)  {    &NBSP; $ request = new GetDetailedBulkDownloadStatusRequest();    &NBSP; $ request-> RequestId = $ requestId;      &NBSP;返回$ proxy-> GetService() - > GetDetailedBulkDownloadStatus($ request) - > ResultFileUrl;  }    功能DownloadFile($ downloadUrl,$ filePath)  {    &NBSP; if(!$ reader = fopen($ downloadUrl,'rb'))    &NBSP; {    &NBSP; &NBSP; &NBSP;抛出新的例外("无法打开网址"。$ downloadUrl。"。");    &NBSP; }      &NBSP; if(!$ writer = fopen($ filePath,'wb'))    &NBSP; {    &NBSP; &NBSP; &NBSP; fclose($ reader);    &NBSP; &NBSP; &NBSP;抛出新的异常("无法创建ZIP文件"。$ filePath。"。");    &NBSP; }      &NBSP; $ bufferSize = 100 * 1024;      &NBSP; while(!feof($ reader))    &NBSP; {    &NBSP; &NBSP; &NBSP; if(false ===($ buffer = fread($ reader,$ bufferSize)))    &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; fclose($ reader);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; fclose($ writer);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;抛出新的例外("从URL读取操作失败。");    &NBSP; &NBSP; &NBSP; }      &NBSP; &NBSP; &NBSP; if(fwrite($ writer,$ buffer)=== false)    &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; fclose($ reader);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; fclose($ writer);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;抛出新的异常("将操作写入ZIP文件失败。");    &NBSP; &NBSP; &NBSP; }    &NBSP; }      &NBSP; fclose($ reader);    &NBSP; fflush($ writer);    &NBSP; fclose($ writer);  }    //解压缩ZIP存档并将内容写入指定的内容文件路径。    函数DecompressFile($ fromZipArchive,$ toExtractedFile)  {    &NBSP; $ archive = new ZipArchive;      &NBSP; if($ archive-> open($ fromZipArchive)=== TRUE){    &NBSP; &NBSP; &NBSP; $ archive-> extractTo(dirname($ toExtractedFile));    &NBSP; &NBSP; &NBSP; $ archive-> close();    &NBSP; }    &NBSP;否则{    &NBSP; &NBSP; &NBSP;抛出新的异常("从ZIP文件解压缩操作失败。");    &NBSP; }  }    //将批量文件压缩到ZIP存档。    函数CompressFile($ fromExtractedFile,$ toZipArchive)  {    &NBSP; $ archive = new ZipArchive;      &NBSP; if($ archive-> open($ toZipArchive,ZipArchive :: OVERWRITE)=== TRUE){    &NBSP; &NBSP; &NBSP; $ archive-> addFile($ fromExtractedFile,basename($ fromExtractedFile));    &NBSP; &NBSP; &NBSP; $ archive-> close();    &NBSP; }    &NBSP;否则{    &NBSP; &NBSP; &NBSP;抛出新的异常("压缩操作到ZIP文件失败。");    &NBSP; }  }    //获取上次下载的时间戳  //下载文件。 SyncTime节点包含时间戳。    函数GetLastSyncTime($ path)  {    &NBSP; $ lastSyncTime = null;      &NBSP; if(is_file($ path))    &NBSP; {    &NBSP; &NBSP; &NBSP; $ reader = @fopen($ path," r");      &NBSP; &NBSP; &NBSP;试试    &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ syncTimeColumn = 0;      &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //第一条记录包含列标题信息,例如"类型"和"同步时间"。    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ record = fgets($ reader);      &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if($ record!= null)    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ fields = explode(",",$ record,100);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ column = 0;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;     &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;做&bbsp; b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ syncTimeColumn =($ fields [$ column] ==" Sync Time")? $ column:$ syncTimeColumn;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; } while($ syncTimeColumn == 0&&(++ $ column< count($ fields)));    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;     &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //在任何其他元数据之后查找帐户记录。      &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ isAccount = false;      &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;做&bbsp; b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ record = fgets($ reader);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ fields = explode(",",$ record,100);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if($ fields [0] ==" Account")    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; date_default_timezone_set(" UTC");    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ date =(new DateTime($ fields [$ syncTimeColumn])) - > format('Y-m-d \TH:i:s');    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ lastSyncTime =($ fields [$ syncTimeColumn]!="")? $ date:null;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ isAccount = true;    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; } while(!$ isAccount);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;     &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; fclose($ reader);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; $ reader = null;      &NBSP; &NBSP; &NBSP; }    &NBSP; &NBSP; &NBSP; catch(例外$ e)    &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(isset($ reader))    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; fclose($ reader);    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }    &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;抛出$ e;    &NBSP; &NBSP; &NBSP; }    &NBSP; }      &NBSP;返回$ lastSyncTime;  }     ?>  &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;     解决方案 您好。 以下是一些建议首先检查: UserName不能是Microsoft帐户(电子邮件格式)。如果您有Microsoft帐户,则必须使用OAuth。有关详细信息,请参阅 使用OAuth管理用户身份验证。 AccountId与您在帐户和帐户中找到的帐号不同。结算页面。帐户详细信息页面应提供帐号和帐户ID,因此请务必使用AccountId。有关如何使用API​​获取AccountId 的示例,请参阅 搜索用户在PHP中的客户。 如果您仍然被阻止,我建议您寻求支持以验证您的凭据。 https:// msdn。 microsoft.com/en-US/library/bing-ads-error-handling-guide.aspx#engagesupport   我希望这有帮助!Hi,I have used below code & get error likeAdApiError Code: 105 Error Code: InvalidCredentials Message: Authentication failed. Either supplied credentials are invalid or the account is inactive. But i have all credentials correctly... <?php// Include the Bing Ads namespaced class files available // for download at http://go.microsoft.com/fwlink/?LinkId=322147 include 'bingads\BulkClasses.php'; include 'bingads\ClientProxy.php';  // Specify the BingAds\Bulk objects that will be used. use BingAds\Bulk\DownloadCampaignsByCampaignIdsRequest; use BingAds\Bulk\BulkDownloadEntity; use BingAds\Bulk\DataScope; use BingAds\Bulk\CampaignScope; use BingAds\Bulk\GetDetailedBulkDownloadStatusRequest; use BingAds\Bulk\DownloadStatus; use BingAds\Bulk\DownloadFileType; use BingAds\Bulk\PerformanceStatsDateRange; use BingAds\Bulk\CustomDateRangeEnd; use BingAds\Bulk\CustomDateRangeStart; use BingAds\Bulk\Date; use BingAds\Bulk\GetBulkUploadUrlRequest; use BingAds\Bulk\ResponseMode; use BingAds\Bulk\GetDetailedBulkUploadStatusRequest;  // 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.$UserName = "******";  //my bing ads username$Password = "******";  //my bing ads password$DeveloperToken = "*******"; //token get from developer page$AccountId = *****;  //In bing billing page$CustomerId = *****;  //In bing billing page// Bulk WSDL  $wsdl = "https://api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/V9/BulkService.svc?singleWsdl";   // The full path to the bulk file.  $BulkFilePath = "c:\\bing\\";  // The full path to the previously extracted bulk file. // This file is used to access the last sync time.  $ExtractedFilePath = "c:\\bulk\\extracted\\accounts.csv";  // The full path to the upload result file.  $UploadResultFilePath = "c:\\bulk\\uploadresults.zip";  // Specifies the bulk file format.  $FileFormat = DownloadFileType::Csv;   // Confirm that the download folder exist; otherwise, exit.  $length = strrpos($BulkFilePath, '\\'); $folder = substr($BulkFilePath, 0, $length);  if (!is_dir($folder)) {     printf("The output folder, %s, does not exist.\nEnsure that the " .         "folder exists and try again.", $folder);     return; }  try {     $proxy = ClientProxy::ConstructWithAccountAndCustomerId($wsdl, $UserName, $Password, $DeveloperToken, $AccountId, $CustomerId, null);      // Use the bulk service to download a bulk file.          // The campaigns must all belong to the same account.          $campaigns = array();          foreach ($CampaignIds as $id)     {         $scope = new CampaignScope();         $scope->CampaignId = $id;         $scope->ParentAccountId = $AccountId;         $campaigns[] = $scope;     }          $dataScope = DataScope::EntityData;          $entities = array (         BulkDownloadEntity::Ads,         BulkDownloadEntity::AdGroups,         BulkDownloadEntity::Campaigns,         BulkDownloadEntity::Keywords         );      $formatVersion = "2.0";          $lastSyncTimeInUTC = GetLastSyncTime($ExtractedFilePath);          // You may include a non-null date range if the lastSyncTime is null, and the data scope includes     // either EntityPerformanceData, BidSuggestionsData, or QualityScoreData.          /*     $performanceStatsDateRange = new PerformanceStatsDateRange();     $performanceStatsDateRange->CustomDateRangeEnd = new Date();     $performanceStatsDateRange->CustomDateRangeEnd->Day = 15;     $performanceStatsDateRange->CustomDateRangeEnd->Month = 9;     $performanceStatsDateRange->CustomDateRangeEnd->Year = 2013;     $performanceStatsDateRange->CustomDateRangeStart = new Date();     $performanceStatsDateRange->CustomDateRangeStart->Day = 15;     $performanceStatsDateRange->CustomDateRangeStart->Month = 9;     $performanceStatsDateRange->CustomDateRangeStart->Year = 2013;     */          // GetDownloadRequestId helper method calls the corresponding Bing Ads service operation     // to request the download identifier.          $downloadRequestId = GetDownloadRequestId(             $proxy,             $campaigns,             $dataScope,             $FileFormat,             $entities,                 $formatVersion,             $lastSyncTimeInUTC,             null             );          $waitTime = 5 * 1;               if ($downloadRequestId != null)     {         printf("Download Request Id: %s\n", $downloadRequestId);          $downloadSuccess = false;              // This sample polls every 30 seconds up to 5 minutes.         // In production you may poll the status every 1 to 2 minutes for up to one hour.         // If the call succeeds, stop polling. If the call or          // download fails, the call throws a fault.              for ($i = 0; $i < 10; $i++)         {             sleep($waitTime);                  // GetDownloadRequestStatus helper method calls the corresponding Bing Ads service operation              // to get the download status.                          $downloadRequestStatus = GetDownloadRequestStatus(                 $proxy,                  $downloadRequestId                 );                  if (($downloadRequestStatus != null) && ($downloadRequestStatus == "Completed"))             {                 $downloadSuccess = true;                 break;             }         }          if ($downloadSuccess)         {             $downloadUrl = GetDownloadUrl(                     $proxy,                     $downloadRequestId                     );             printf("Downloading from %s.\n\n", $downloadUrl);             DownloadFile($downloadUrl, $BulkFilePath);             printf("The download file was written to %s.\n", $BulkFilePath);                      }         else // Pending         {             printf("The request is taking longer than expected.\n " .                     "Save the download request ID (%s) and try again later.\n",                     $downloadRequestId);         }     }          } catch (SoapFault $e) {     // Output the last request/response.          print "\nLast SOAP request/response:\n";     print $proxy->GetWsdl() . "\n";     print $proxy->GetService()->__getLastRequest()."\n";     print $proxy->GetService()->__getLastResponse()."\n";          // Bulk service operations can throw AdApiFaultDetail.     if (isset($e->detail->AdApiFaultDetail))     {         // Log this fault.          print "The operation failed with the following faults:\n";          $errors = is_array($e->detail->AdApiFaultDetail->Errors->AdApiError)                 ? $e->detail->AdApiFaultDetail->Errors->AdApiError                 : array('AdApiError' => $e->detail->AdApiFaultDetail->Errors->AdApiError);          // If the AdApiError array is not null, the following are examples of error codes that may be found.         foreach ($errors as $error)         {             print "AdApiError\n";             printf("Code: %d\nError Code: %s\nMessage: %s\n", $error->Code, $error->ErrorCode, $error->Message);              switch ($error->Code)             {                 case 0:    // InternalError                     break;                 case 105:  // InvalidCredentials                     break;                 default:                     print "Please see MSDN documentation for more details about the error code output above.\n";                     break;             }         }     }      // Bulk service operations can throw ApiFaultDetail.     elseif (isset($e->detail->ApiFaultDetail))     {         // Log this fault.          print "The operation failed with the following faults:\n";          // If the BatchError array is not null, the following are examples of error codes that may be found.         if (!empty($e->detail->ApiFaultDetail->BatchErrors))         {             $errors = is_array($e->detail->ApiFaultDetail->BatchErrors->BatchError)                     ? $e->detail->ApiFaultDetail->BatchErrors->BatchError                     : array('BatchError' => $e->detail->ApiFaultDetail->BatchErrors->BatchError);              foreach ($errors as $error)             {                 printf("BatchError at Index: %d\n", $error->Index);                 printf("Code: %d\nError Code: %s\nMessage: %s\n", $error->Code, $error->ErrorCode, $error->Message);                  switch ($error->Code)                 {                     case 0:     // InternalError                         break;                     default:                         print "Please see MSDN documentation for more details about the error code output above.\n";                         break;                 }             }         }          // If the OperationError array is not null, the following are examples of error codes that may be found.         if (!empty($e->detail->ApiFaultDetail->OperationErrors))         {             $errors = is_array($e->detail->ApiFaultDetail->OperationErrors->OperationError)                     ? $e->detail->ApiFaultDetail->OperationErrors->OperationError                     : array('OperationError' => $e->detail->ApiFaultDetail->OperationErrors->OperationError);              foreach ($errors as $error)             {                 print "OperationError\n";                 printf("Code: %d\nError Code: %s\nMessage: %s\n", $error->Code, $error->ErrorCode, $error->Message);                  switch ($error->Code)                 {                     case 0:     // InternalError                         break;                     case 106:   // UserIsNotAuthorized                         break;                     default:                         print "Please see MSDN documentation for more details about the error code output above.\n";                         break;                 }             }         }     } } 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";     } }  // GetDownloadRequestId helper method calls the DownloadCampaignsByCampaignIds service operation  // to request the download identifier.          function GetDownloadRequestId($proxy, $campaigns, $dataScope, $downloadFileType,          $entities, $formatVersion, $lastSyncTimeInUTC, $performanceStatsDateRange) {     // Set the request information.     $request = new DownloadCampaignsByCampaignIdsRequest();     $request->Campaigns = $campaigns;     $request->DataScope = $dataScope;     $request->DownloadFileType = $downloadFileType;     $request->Entities = $entities;     $request->FormatVersion = $formatVersion;     $request->LastSyncTimeInUTC = $lastSyncTimeInUTC;     $request->PerformanceStatsDateRange = $performanceStatsDateRange;              return $proxy->GetService()->DownloadCampaignsByCampaignIds($request)->DownloadRequestId; }   // GetDownloadRequestStatus helper method calls the GetDetailedBulkDownloadStatus service operation  // to get the download request status.  function GetDownloadRequestStatus($proxy, $requestId) {     $request = new GetDetailedBulkDownloadStatusRequest();     $request->RequestId = $requestId;      return $proxy->GetService()->GetDetailedBulkDownloadStatus($request)->RequestStatus; }  // GetDownloadUrl helper method calls the GetDetailedBulkDownloadStatus service operation  // to get the download Url.  function GetDownloadUrl($proxy, $requestId) {     $request = new GetDetailedBulkDownloadStatusRequest();     $request->RequestId = $requestId;      return $proxy->GetService()->GetDetailedBulkDownloadStatus($request)->ResultFileUrl; }  function DownloadFile($downloadUrl, $filePath) {     if (!$reader = fopen($downloadUrl, 'rb'))     {         throw new Exception("Failed to open URL " . $downloadUrl . ".");     }      if (!$writer = fopen($filePath, 'wb'))     {         fclose($reader);         throw new Exception("Failed to create ZIP file " . $filePath . ".");     }      $bufferSize = 100 * 1024;      while (!feof($reader))     {         if (false === ($buffer = fread($reader, $bufferSize)))         {             fclose($reader);             fclose($writer);             throw new Exception("Read operation from URL failed.");         }          if (fwrite($writer, $buffer) === false)         {             fclose($reader);             fclose($writer);             throw new Exception ("Write operation to ZIP file failed.");         }     }      fclose($reader);     fflush($writer);     fclose($writer); }  // Decompresses a ZIP Archive and writes the contents to the specified file path.  function DecompressFile($fromZipArchive, $toExtractedFile) {     $archive = new ZipArchive;      if ($archive->open($fromZipArchive) === TRUE) {         $archive->extractTo(dirname($toExtractedFile));         $archive->close();     }     else {         throw new Exception ("Decompress operation from ZIP file failed.");     } }  // Compresses a bulk file to a ZIP Archive.  function CompressFile($fromExtractedFile, $toZipArchive) {     $archive = new ZipArchive;      if ($archive->open($toZipArchive, ZipArchive::OVERWRITE) === TRUE) {         $archive->addFile($fromExtractedFile, basename($fromExtractedFile));         $archive->close();     }     else {         throw new Exception ("Compress operation to ZIP file failed.");     } }  // Get the time stamp of the last download from the previous // download file. The SyncTime node contains the time stamp.  function GetLastSyncTime($path) {     $lastSyncTime = null;      if (is_file($path))     {         $reader = @fopen($path, "r");          try         {             $syncTimeColumn = 0;              // The first record contains column header information, for example "Type" and "Sync Time".             $record = fgets($reader);              if($record != null)             {                 $fields = explode(",", $record, 100);                 $column = 0;                                  do                 {                     $syncTimeColumn = ($fields[$column] == "Sync Time") ? $column : $syncTimeColumn;                 } while($syncTimeColumn == 0 && (++$column < count($fields)));             }                          // Look for the Account record after any other metadata.              $isAccount = false;              do             {                 $record = fgets($reader);                 $fields = explode(",", $record, 100);                 if($fields[0] == "Account")                 {                     date_default_timezone_set("UTC");                     $date = (new DateTime($fields[$syncTimeColumn]))->format('Y-m-d\TH:i:s');                     $lastSyncTime = ($fields[$syncTimeColumn] != "") ? $date : null;                     $isAccount = true;                 }             } while(!$isAccount);                          fclose($reader);             $reader = null;          }         catch (Exception $e)         {             if (isset($reader))             {                 fclose($reader);             }             throw $e;         }     }      return $lastSyncTime; }   ?>                    解决方案 Hello.Here are a couple of suggestions to check first:UserName cannot be a Microsoft account (email format). If you have a Microsoft account, you must use OAuth. For more information, please seeManaging User Authentication with OAuth.AccountId is not the same as Account Number that you would find on the Accounts & Billing page. The account details page should provide both Account Number and Account Id, so please be sure to use the AccountId. For an example of how to get the AccountId using the API, please seeSearch Customers by User in PHP.If you are still blocked, I suggest reaching out to support to verify your credentials.https://msdn.microsoft.com/en-US/library/bing-ads-error-handling-guide.aspx#engagesupport I hope this helps! 这篇关于凭据错误无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 12:10