【问题标题】:Convert micros to currency in AWQL csv report with Adwords API使用 Adwords API 在 AWQL csv 报告中将微量转换为货币
【发布时间】:2014-09-13 03:44:16
【问题描述】:

我在 AWQL 中有这个查询,我使用 ReportUtils::DownloadReportWithAwql 得到 CSV 格式的响应

select Date, Clicks, Cost from ACCOUNT_PERFORMANCE_REPORT during LAST_30_DAYS

我需要将 CSV 中的成本数据从微观转换为帐户中的货币 (Cost / 1000000)。

我还需要能够使用 any AWQL 查询转换响应中的任何 Cost 数据,例如,该解决方案也必须适用于该查询:

SELECT CampaignName, KeywordText, Cost, CostPerConversion, QualityScore FROM KEYWORDS_PERFORMANCE_REPORT DURING LAST_7_DAYS

从 v201406 开始,returnMoneyInMicros 标头不再有效,值始终以 micros 形式返回。 https://developers.google.com/adwords/api/docs/guides/reporting-concepts#money

这是我在 stackoverflow 中的第一个问题。

【问题讨论】:

  • @drep 我进行了 2 个查询,结果是 here 现在假设您在 $variable1 中有 cost1,在 $variable2 中有 cost2。如何使用相同的函数将变量中的成本和成本/转换列除以 1000000?

标签: php csv google-ads-api adwords-budgetservice


【解决方案1】:

最后我做到了,对我来说效果很好。

    //data is a string with data in micros in csv format
    $data = $this->DownloadCriteriaReportWithAwql($awql);

    //start micros conversion
    $count = 0;
    $costpos = array();
    $newarray = array();
    foreach(preg_split("/((\r?\n)|(\r\n?))/", $data) as $line){

        $linearray = str_getcsv($line);

        if($count == 0) {
            //adwords report title
            $newarray[] = $linearray;
            $count++;
            continue;
        }

        if($count == 1) {
            //columns report header
            $postvalue = 0;

            foreach($linearray as $value){
                if (strpos($value,'Cost') !== false) {
                    $costpos[] = $postvalue;
                }
                $postvalue++;
            }

            $newarray[] = $linearray;
            $count++;
            continue;
        }

        if(!empty($costpos)) {

            foreach($costpos as $costpostval){

                if(isset($linearray[$costpostval])) {
                    $linearray[$costpostval] = $linearray[$costpostval] / 1000000;
                }

            }
        }

        $newarray[] = $linearray;
        $count++;
    }


    $tmpfname = tempnam(sys_get_temp_dir(), "FOO");
    $outstream = fopen($tmpfname, "r+");
    foreach($newarray as $newline){
        fputcsv($outstream, $newline);
    }
    fclose($outstream);
    //end micros conversion - $tmpfname temp file with cost in currency csv formated

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-05
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-28
    相关资源
    最近更新 更多