Hi Nema,
Thank you for your patience with this issue. I have created an example that can be run from the console to help solve this problem. To run the sample, follow the steps below:
php admob_api_sample.php
admob_api_sample.php
<?php /* * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /************************************************ ATTENTION: Change this path to point to your vendor folder if your project directory structure differs from this repository's! ************************************************/ require_once __DIR__ . '/vendor/autoload.php'; use Examples\Reports\GenerateMediationReport; use Examples\Reports\GenerateNetworkReport; use Examples\Accounts\ListAccounts; use Examples\Accounts\GetAccount; use function HtmlHelper\pageHeader; use function HtmlHelper\pageFooter; session_start(); // Configure token storage on disk. // Store refresh tokens in a local disk file. define('STORE_ON_DISK', true); define('TOKEN_FILENAME', 'tokens.dat'); $client = new Google_Client(); $client->addScope('https://www.googleapis.com/auth/admob.report'); $client->setApplicationName('AdMob API PHP Quickstart'); $client->setAccessType('offline'); // Be sure to replace the contents of client_secrets.json with your developer // credentials. $client->setAuthConfig('client_secrets.json'); $service = new Google_Service_AdMob($client); // If we have an access token, we can make requests, else we generate an // authentication URL. if ( STORE_ON_DISK && file_exists(TOKEN_FILENAME) && filesize(TOKEN_FILENAME) > 0 ) { $client->refreshToken(file_get_contents(TOKEN_FILENAME)); } else { // Begin the OAuth 2.0 flow by generating an authentication URL. $authUrl = $client->createAuthUrl(); echo "Click on the " . $authUrl . " to retrieve your access code \n\n"; $code = readline("Enter your access code: "); // Exchange code from OAuth 2.0 flow with the authenticate() function. $accessToken = $client->fetchAccessTokenWithAuthCode($code); $refreshToken = $client->getRefreshToken(); if (STORE_ON_DISK) { file_put_contents(TOKEN_FILENAME, $refreshToken); } } echo 'AdMob API samples'; // Now we're signed in, we can make our requests. makeRequests($service); // Makes all the API requests. function makeRequests($service) { /* * The first account from the list of accounts is being used as input * for the following requests. * * For other accounts, replace 'account_name' below which follows the format * "accounts/pub-XXXXXXXXXXXXXXXX". * See https://support.google.com/admob/answer/2784578 * for instructions on how to find your account name. */ $accountName = ListAccounts::getFirstAccountName($service); if (isset($accountName)) { ListAccounts::run($service); GetAccount::run($service, $accountName); GenerateNetworkReport::run($service, $accountName); GenerateMediationReport::run($service, $accountName); } else { echo 'Please specify the account_name, which should follow a format of "accounts/pub-XXXXXXXXXXXXXXXX". See https://support.google.com/admob/answer/2784578 for instructions on how to find your account name.'; } }
Please do not hesitate to reach out if you have any additional questions or concerns.
All the best,
|
||||||
Hi Nema,