php 对接Inmobi海外广告平台收益接口Reporting API

今天对接的是Inmobi广告reporting api接口,拉取广告收益回来自己做统计。记录分享给大家
首先是文档地址,进入到Inmobi后台就能看到文档地址以及参数:
文档地址:https://support.inmobi.com/monetize/reporting-api#generating-api-key
在这里插入图片描述
在这里插入图片描述

接入这些第三方广告平台,流程基本上一样,拿好参数之后可以直接开始对接了,我直接贴代码出来:

const Auth_Url = "https://api.inmobi.com/v1.0/generatesession/generate";
const serverHost = "https://api.inmobi.com/v3.0/reporting/publisher";

$authHeaders = array(
            "userName" => self::Developer_Id,
            "secretKey" => self::Api_Key
        );
        $client = new Client();
        $response = $client->request('GET', self::Auth_Url, ['headers' => $authHeaders]);
        $result = json_decode($response->getBody()->getContents(), true);

        if ($result['error']) {
            return ['code' => 101, 'msg' => 'api report error!!'];
        }

        $param = [
            'reportRequest' => [
                'timeFrame' => "$date:$date",
                'groupBy' => ["date", "platform", "inmobiAppId", "placement"],
                'metrics' => ["adRequests", "adImpressions", "clicks", "earnings", "servedImpressions", "fillRate"],
                'filterBy' => [
                    ['filterName' => "inmobiAppId", "filterValue" => array_keys($third_apps), "comparator" => "IN"]
                ]
            ],
        ];
        $headers = array(
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
            'accountId' => $result['respList'][0]['accountId'],
            'secretKey' => self::Api_Key,
            'sessionId' => $result['respList'][0]['sessionId'],
        );
        $response = $client->request('POST', self::serverHost, ['headers' => $headers, 'json' => $param]);
        $result = json_decode($response->getBody()->getContents(), true);
        $model_type = [
            'Android' => 1,
            'iOS' => 2,
        ];
        ......下面是自己的逻辑代码

需要注意的几个点就是,请求头设置,按照文档要求,需要先将后台的参数,换取一个accountId,和一个sessionId,返回的数据和groupby的数据也是比较少,就看到只有这么几个,

$param = [
            'reportRequest' => [
                'timeFrame' => "$date:$date",
                'groupBy' => ["date", "platform", "inmobiAppId", "placement"],
                'metrics' => ["adRequests", "adImpressions", "clicks", "earnings", "servedImpressions", "fillRate"],
                'filterBy' => [
                    ['filterName' => "inmobiAppId", "filterValue" => array_keys($third_apps), "comparator" => "IN"]
                ]
            ],
        ];

上面我们只拿我们需要的应用数据类型为数组,自己组装好

$model_type = [
            'Android' => 1,
            'iOS' => 2,
        ];
  

然后就是返回设备类型,安卓返回的是Android,苹果返回的是iOS,大家根据自己的需要存储
以上是我对接Inmobi广告收益接口代码,欢迎大家交流学习,希望能对你有帮助。

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-19 20:34:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-19 20:34:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-19 20:34:03       87 阅读
  4. Python语言-面向对象

    2024-03-19 20:34:03       96 阅读

热门阅读

  1. 2079: [蓝桥杯2023初赛] 冶炼金属

    2024-03-19 20:34:03       42 阅读
  2. 小型路由器,为什么四个端口的IP在一个网段?

    2024-03-19 20:34:03       45 阅读
  3. Transformer大模型学习导引:光速掌握大模型

    2024-03-19 20:34:03       54 阅读
  4. 文件上传漏洞或预习文件包含漏洞

    2024-03-19 20:34:03       45 阅读
  5. Visual Studio 常用快捷键与设置

    2024-03-19 20:34:03       46 阅读