本文主要是介绍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广告收益接口代码,欢迎大家交流学习,希望能对你有帮助。
这篇关于php 对接Inmobi海外广告平台收益接口Reporting API的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!