google 广告系列 、 预算、 账号列表
This commit is contained in:
parent
ce93c4cc48
commit
d771a95c42
@ -2,111 +2,127 @@
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use app\model\Ad;
|
||||
use app\model\AdGroup;
|
||||
use app\model\Campaign;
|
||||
use app\model\CampaignBudget;
|
||||
use app\service\GoogleAdsService;
|
||||
//use Webman\Controller;
|
||||
use Google\ApiCore\ApiException;
|
||||
use support\Request;
|
||||
use app\service\GoogleAdsCampaignService;
|
||||
use app\service\GoogleAdsAccountService;
|
||||
use support\Response;
|
||||
use DI\Annotation\Inject;
|
||||
|
||||
class GoogleAdsController extends Controller
|
||||
class GoogleAdsController
|
||||
{
|
||||
protected $googleAdsService;
|
||||
/**
|
||||
* @Inject
|
||||
* @var GoogleAdsCampaignService
|
||||
*/
|
||||
|
||||
private $googleAdsCampaignService;
|
||||
|
||||
/**
|
||||
* @Inject
|
||||
* @var GoogleAdsAccountService
|
||||
*/
|
||||
private $googleAdsAccountService;
|
||||
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->googleAdsService = new GoogleAdsService();
|
||||
|
||||
}
|
||||
|
||||
// 创建广告预算
|
||||
public function createCampaignBudget($request): \support\Response
|
||||
public function createCampaign(Request $request)
|
||||
{
|
||||
$data = $request->post();
|
||||
$customerId = $data['customer_id'];
|
||||
$budgetName = $data['budget_name'];
|
||||
$amountMicros = $data['amount_micros'];
|
||||
$options = $request->all();
|
||||
|
||||
$budgetResourceName = $this->googleAdsService->createCampaignBudget($customerId, $budgetName, $amountMicros);
|
||||
|
||||
// 在数据库中保存广告预算信息
|
||||
$budget = new CampaignBudget([
|
||||
'name' => $budgetName,
|
||||
'amount_micros' => $amountMicros,
|
||||
]);
|
||||
$budget->save();
|
||||
return $this->successResponse(['status' =>'success', 'data' => $budgetResourceName]);
|
||||
|
||||
// return json(['status' => 'success', 'data' => $budgetResourceName]);
|
||||
// 继续处理 Google Ads API 操作
|
||||
return $this->addCampaign($options);
|
||||
}
|
||||
|
||||
// 创建广告系列
|
||||
public function createCampaign($request): \support\Response
|
||||
public function createCampaignBudget(Request $request)
|
||||
{
|
||||
$data = $request->post();
|
||||
$customerId = $data['customer_id'];
|
||||
$budgetId = $data['budget_id'];
|
||||
$campaignName = $data['campaign_name'];
|
||||
|
||||
$campaignResourceName = $this->googleAdsService->createCampaign($customerId, $budgetId, $campaignName);
|
||||
|
||||
// 在数据库中保存广告系列信息
|
||||
$campaign = new Campaign([
|
||||
'name' => $campaignName,
|
||||
'budget_id' => $budgetId,
|
||||
]);
|
||||
$campaign->save();
|
||||
|
||||
// return json(['status' => 'success', 'data' => $campaignResourceName]);
|
||||
return $this->successResponse(['status' =>'success', 'data' => $campaignResourceName]);
|
||||
$options = $request->all();
|
||||
// return json(['code' => 0, 'msg' => getenv('GOOGLE_ADS_CUSTOMER_ID'),'data'=>$options]);
|
||||
// 继续处理 Google Ads API 操作
|
||||
return $this->addCampaignBudget($options);
|
||||
}
|
||||
|
||||
// 创建广告组
|
||||
public function createAdGroup($request): \support\Response
|
||||
public function createLinkManagerToClient(Request $request)
|
||||
{
|
||||
$data = $request->post();
|
||||
$customerId = $data['customer_id'];
|
||||
$campaignId = $data['campaign_id'];
|
||||
$adGroupName = $data['ad_group_name'];
|
||||
$cpcBidMicros = $data['cpc_bid_micros'];
|
||||
|
||||
$adGroupResourceName = $this->googleAdsService->createAdGroup($customerId, $campaignId, $adGroupName, $cpcBidMicros);
|
||||
|
||||
// 在数据库中保存广告组信息
|
||||
$adGroup = new AdGroup([
|
||||
'name' => $adGroupName,
|
||||
'campaign_id' => $campaignId,
|
||||
'cpc_bid_micros' => $cpcBidMicros,
|
||||
]);
|
||||
$adGroup->save();
|
||||
|
||||
// return json(['status' => 'success', 'data' => $adGroupResourceName]);
|
||||
return $this->successResponse(['status' =>'success', 'data' => $adGroupResourceName]);
|
||||
$options = $request->all();
|
||||
// 继续处理 Google Ads API 操作
|
||||
return $this->addLinkManagerToClient($options);
|
||||
}
|
||||
|
||||
// 创建广告
|
||||
public function createAd($request): \support\Response
|
||||
public function accessibleCustomers(Request $request)
|
||||
{
|
||||
$data = $request->post();
|
||||
$customerId = $data['customer_id'];
|
||||
$adGroupId = $data['ad_group_id'];
|
||||
$adName = $data['ad_name'];
|
||||
$headline = $data['headline'];
|
||||
$description = $data['description'];
|
||||
$finalUrls = $data['final_urls'];
|
||||
|
||||
$adResourceName = $this->googleAdsService->createAd($customerId, $adGroupId, $adName, $headline, $description, $finalUrls);
|
||||
|
||||
// 在数据库中保存广告信息
|
||||
$ad = new Ad([
|
||||
'name' => $adName,
|
||||
'ad_group_id' => $adGroupId,
|
||||
'headline' => $headline,
|
||||
'description' => $description,
|
||||
'final_urls' => json_encode($finalUrls),
|
||||
]);
|
||||
$ad->save();
|
||||
|
||||
// return json(['status' => 'success', 'data' => $adResourceName]);
|
||||
return $this->successResponse(['status' =>'success', 'data' => $adResourceName]);
|
||||
// $options = $request->all();
|
||||
// 继续处理 Google Ads API 操作
|
||||
return $this->listAccessibleCustomers();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建广告系列
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function addCampaign($options): Response
|
||||
{
|
||||
// 使用 $options 数组中的数据进行 Google Ads API 的调用
|
||||
// 例如使用 $options['customer_id'] 和 $options['feed_id']
|
||||
// 调用相应的 Google Ads 服务
|
||||
// $budgetResourceName = $this->googleAdsCampaignBudgetService->createCampaignBudget();
|
||||
$campaignResourceName = $this->googleAdsCampaignService->runAddCampaign(4060397299, $options);
|
||||
return $this->successResponse(['campaignResourceName' => $campaignResourceName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建广告预算
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function addCampaignBudget($options): Response
|
||||
{
|
||||
$budgetResourceName = $this->googleAdsCampaignService->runAddCampaignBudget(0, $options);
|
||||
return $this->successResponse(['budgetResourceName' => $budgetResourceName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联广告客户ID
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function addLinkManagerToClient($options): Response
|
||||
{
|
||||
$linkResourceName = $this->googleAdsAccountService->runLinkManagerToClient($options);
|
||||
return $this->successResponse(['linkResourceName' => $linkResourceName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联广告客户ID
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function listAccessibleCustomers(): Response
|
||||
{
|
||||
$linkResourceName = $this->googleAdsAccountService->runListAccessibleCustomers();
|
||||
return $this->successResponse(['linkResourceName' => $linkResourceName]);
|
||||
}
|
||||
|
||||
// 可以加入一些公共方法
|
||||
protected function successResponse($data): Response
|
||||
{
|
||||
return Json([
|
||||
'code' => 200,
|
||||
'status' => 'success',
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function errorResponse($message): Response
|
||||
{
|
||||
return Json([
|
||||
'code' => 400,
|
||||
'status' => 'error',
|
||||
'message' => $message,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
305
app/service/GoogleAdsAccountService.php
Normal file
305
app/service/GoogleAdsAccountService.php
Normal file
@ -0,0 +1,305 @@
|
||||
<?php
|
||||
|
||||
namespace app\service;
|
||||
|
||||
use app\util\Helper;
|
||||
use app\util\ArgumentNames;
|
||||
use app\util\ArgumentParser;
|
||||
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
|
||||
use Google\Ads\GoogleAds\Lib\V18\GoogleAdsClient;
|
||||
use Google\Ads\GoogleAds\Lib\V18\GoogleAdsClientBuilder;
|
||||
use Google\Ads\GoogleAds\Lib\V18\GoogleAdsException;
|
||||
use Google\Ads\GoogleAds\Util\FieldMasks;
|
||||
use Google\Ads\GoogleAds\Util\V18\ResourceNames;
|
||||
use Google\Ads\GoogleAds\V18\Enums\ManagerLinkStatusEnum\ManagerLinkStatus;
|
||||
use Google\Ads\GoogleAds\V18\Errors\GoogleAdsError;
|
||||
use Google\Ads\GoogleAds\V18\Resources\CustomerClientLink;
|
||||
use Google\Ads\GoogleAds\V18\Resources\CustomerManagerLink;
|
||||
use Google\Ads\GoogleAds\V18\Services\CustomerClientLinkOperation;
|
||||
use Google\Ads\GoogleAds\V18\Services\CustomerManagerLinkOperation;
|
||||
use Google\Ads\GoogleAds\V18\Services\ListAccessibleCustomersRequest;
|
||||
use Google\Ads\GoogleAds\V18\Services\MutateCustomerClientLinkRequest;
|
||||
use Google\Ads\GoogleAds\V18\Services\MutateCustomerManagerLinkRequest;
|
||||
use Google\Ads\GoogleAds\V18\Services\SearchGoogleAdsRequest;
|
||||
use Google\ApiCore\ApiException;
|
||||
|
||||
class GoogleAdsAccountService
|
||||
{
|
||||
// private $googleAdsClient;
|
||||
// private $customerId;
|
||||
// private const NUMBER_OF_CAMPAIGNS_TO_ADD = 1;
|
||||
private $loginCustomerId; // 增加 login-customer-id 属性
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// $this->customerId = getenv('GOOGLE_ADS_CUSTOMER_ID');
|
||||
//
|
||||
// // OAuth2 Token Authentication
|
||||
// $oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
|
||||
//
|
||||
// // Google Ads Client initialization
|
||||
// $this->googleAdsClient = (new GoogleAdsClientBuilder())
|
||||
// ->fromFile()
|
||||
// ->withOAuth2Credential($oAuth2Credential)
|
||||
// ->build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the example.
|
||||
*
|
||||
* @param GoogleAdsClient $googleAdsClient the Google Ads API client
|
||||
*/
|
||||
// [START list_accessible_customers]
|
||||
public static function runListAccessibleCustomers()
|
||||
{
|
||||
// Creates a client with the manager customer ID as login customer ID.
|
||||
$googleAdsClient = self::createGoogleAdsClient(0);
|
||||
|
||||
$customerServiceClient = $googleAdsClient->getCustomerServiceClient();
|
||||
|
||||
// Issues a request for listing all accessible customers.
|
||||
$accessibleCustomers =
|
||||
$customerServiceClient->listAccessibleCustomers(new ListAccessibleCustomersRequest());
|
||||
print 'Total results: ' . count($accessibleCustomers->getResourceNames()) . PHP_EOL;
|
||||
|
||||
$resourceNameArray = [];
|
||||
// Iterates over all accessible customers' resource names and prints them.
|
||||
foreach ($accessibleCustomers->getResourceNames() as $resourceName) {
|
||||
/** @var string $resourceName */
|
||||
printf("Customer resource name: '%s'%s", $resourceName, PHP_EOL);
|
||||
$resourceNameArray[] = $resourceName;
|
||||
}
|
||||
return $resourceNameArray;
|
||||
}
|
||||
// [END list_accessible_customers]
|
||||
|
||||
|
||||
/**
|
||||
* Runs the example.
|
||||
*
|
||||
* @param $options
|
||||
* This example assumes that the same credentials will work for both customers,
|
||||
* but that may not be the case. If you need to use different credentials
|
||||
* for each customer, then you may either update the client configuration or
|
||||
* instantiate the clients accordingly, one for each set of credentials. Always make
|
||||
* sure to update the configuration before fetching any services you need to use.
|
||||
* // * @return mixed
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function runLinkManagerToClient($options)
|
||||
{
|
||||
|
||||
// Extends an invitation to the client while authenticating as the manager.
|
||||
$managerCustomerId = $options['manager_customer_id'];
|
||||
$clientCustomerId = $options['client_customer_id'];
|
||||
|
||||
|
||||
// Extends an invitation to the client while authenticating as the manager.
|
||||
$customerClientLinkResourceName = self::createInvitation(
|
||||
$managerCustomerId,
|
||||
$clientCustomerId
|
||||
|
||||
);
|
||||
|
||||
// Retrieves the manager link information.
|
||||
$managerLinkResourceName = self::getManagerLinkResourceName(
|
||||
$managerCustomerId,
|
||||
$clientCustomerId,
|
||||
$customerClientLinkResourceName
|
||||
);
|
||||
|
||||
// Accepts the manager's invitation while authenticating as the client.
|
||||
return self::acceptInvitation($clientCustomerId, $managerLinkResourceName);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends an invitation from a manager customer to a client customer.
|
||||
*
|
||||
* @param int $managerCustomerId the manager customer ID
|
||||
* @param int $clientCustomerId the customer ID
|
||||
* @return string the resource name of the customer client link created for the invitation
|
||||
*/
|
||||
private static function createInvitation(
|
||||
int $managerCustomerId,
|
||||
int $clientCustomerId
|
||||
)
|
||||
{
|
||||
|
||||
// Creates a client with the manager customer ID as login customer ID.
|
||||
$googleAdsClient = self::createGoogleAdsClient($managerCustomerId);
|
||||
|
||||
// Creates a customer client link.
|
||||
$customerClientLink = new CustomerClientLink([
|
||||
// Sets the client customer to invite.
|
||||
'client_customer' => ResourceNames::forCustomer($clientCustomerId),
|
||||
'status' => ManagerLinkStatus::PENDING
|
||||
]);
|
||||
|
||||
// Creates a customer client link operation for creating the one above.
|
||||
$customerClientLinkOperation = new CustomerClientLinkOperation();
|
||||
$customerClientLinkOperation->setCreate($customerClientLink);
|
||||
|
||||
// Issues a mutate request to create the customer client link.
|
||||
$customerClientLinkServiceClient = $googleAdsClient->getCustomerClientLinkServiceClient();
|
||||
$response = $customerClientLinkServiceClient->mutateCustomerClientLink(
|
||||
MutateCustomerClientLinkRequest::build(
|
||||
$managerCustomerId,
|
||||
$customerClientLinkOperation
|
||||
)
|
||||
);
|
||||
|
||||
// Prints the result.
|
||||
$customerClientLinkResourceName = $response->getResult()->getResourceName();
|
||||
printf(
|
||||
"An invitation has been extended from the manager customer %d" .
|
||||
" to the client customer %d with the customer client link resource name '%s'.%s",
|
||||
$managerCustomerId,
|
||||
$clientCustomerId,
|
||||
$customerClientLinkResourceName,
|
||||
PHP_EOL
|
||||
);
|
||||
|
||||
// Returns the resource name of the created customer client link.
|
||||
return $customerClientLinkResourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the manager link resource name of a customer client link given its resource name.
|
||||
*
|
||||
* @param int $managerCustomerId the manager customer ID
|
||||
* @param int $clientCustomerId the customer ID
|
||||
* @param string $customerClientLinkResourceName the customer client link resource name
|
||||
* @return string the manager link resource name
|
||||
*/
|
||||
private static function getManagerLinkResourceName(
|
||||
int $managerCustomerId,
|
||||
int $clientCustomerId,
|
||||
string $customerClientLinkResourceName
|
||||
)
|
||||
{
|
||||
// Creates a client with the manager customer ID as login customer ID.
|
||||
$googleAdsClient = self::createGoogleAdsClient($managerCustomerId);
|
||||
|
||||
// Creates the query.
|
||||
$query = "SELECT customer_client_link.manager_link_id FROM customer_client_link" .
|
||||
" WHERE customer_client_link.resource_name = '$customerClientLinkResourceName'";
|
||||
|
||||
// Issues a search request.
|
||||
$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
|
||||
$response = $googleAdsServiceClient->search(
|
||||
SearchGoogleAdsRequest::build($managerCustomerId, $query)
|
||||
);
|
||||
|
||||
// Gets the ID and resource name associated to the manager link found.
|
||||
$managerLinkId = $response->getIterator()->current()
|
||||
->getCustomerClientLink()
|
||||
->getManagerLinkId();
|
||||
$managerLinkResourceName = ResourceNames::forCustomerManagerLink(
|
||||
$clientCustomerId,
|
||||
$managerCustomerId,
|
||||
$managerLinkId
|
||||
);
|
||||
|
||||
// Prints the result.
|
||||
printf(
|
||||
"Retrieved the manager link of the customer client link:" .
|
||||
" its ID is %d and its resource name is '%s'.%s",
|
||||
$managerLinkId,
|
||||
$managerLinkResourceName,
|
||||
PHP_EOL
|
||||
);
|
||||
|
||||
// Returns the resource name of the manager link found.
|
||||
return $managerLinkResourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts an invitation.
|
||||
*
|
||||
* @param int $clientCustomerId the customer ID
|
||||
* @param string $managerLinkResourceName the resource name of the manager link to accept
|
||||
*/
|
||||
private static function acceptInvitation(
|
||||
int $clientCustomerId,
|
||||
string $managerLinkResourceName
|
||||
)
|
||||
{
|
||||
// Creates a client with the client customer ID as login customer ID.
|
||||
$googleAdsClient = self::createGoogleAdsClient($clientCustomerId);
|
||||
|
||||
// Creates the customer manager link with the updated status.
|
||||
$customerManagerLink = new CustomerManagerLink();
|
||||
$customerManagerLink->setResourceName($managerLinkResourceName);
|
||||
$customerManagerLink->setStatus(ManagerLinkStatus::ACTIVE);
|
||||
|
||||
// Creates a customer manager link operation for updating the one above.
|
||||
$customerManagerLinkOperation = new CustomerManagerLinkOperation();
|
||||
$customerManagerLinkOperation->setUpdate($customerManagerLink);
|
||||
$customerManagerLinkOperation->setUpdateMask(
|
||||
FieldMasks::allSetFieldsOf($customerManagerLink)
|
||||
);
|
||||
|
||||
// Issues a mutate request to update the customer manager link.
|
||||
$customerManagerLinkServiceClient =
|
||||
$googleAdsClient->getCustomerManagerLinkServiceClient();
|
||||
$response = $customerManagerLinkServiceClient->mutateCustomerManagerLink(
|
||||
MutateCustomerManagerLinkRequest::build(
|
||||
$clientCustomerId,
|
||||
[$customerManagerLinkOperation]
|
||||
)
|
||||
);
|
||||
|
||||
// Prints the result.
|
||||
printf(
|
||||
"The client %d accepted the invitation with the resource name '%s'.%s",
|
||||
$clientCustomerId,
|
||||
$response->getResults()[0]->getResourceName(),
|
||||
PHP_EOL
|
||||
);
|
||||
return $response->getResults()[0]->getResourceName();
|
||||
}
|
||||
// [END link_manager_to_client]
|
||||
|
||||
/**
|
||||
* Creates a Google Ads client based on the default configuration file
|
||||
* and a given login customer id.
|
||||
*
|
||||
* @param int $loginCustomerId the login customer ID
|
||||
* @return GoogleAdsClient the created client
|
||||
*/
|
||||
private static function createGoogleAdsClient(int $loginCustomerId)
|
||||
{
|
||||
// Generates a refreshable OAuth2 credential for authentication.
|
||||
$oAuth2Credential = (new OAuth2TokenBuilder())
|
||||
// Sets the properties based on the default properties file
|
||||
->fromFile()
|
||||
->build();
|
||||
|
||||
if($loginCustomerId >0){
|
||||
// Builds and returns the Google Ads client
|
||||
return (new GoogleAdsClientBuilder())
|
||||
// Sets the properties based on the default properties file
|
||||
->fromFile()
|
||||
// eUses the OAuth2 credentials crated above.
|
||||
->withOAuth2Credential($oAuth2Credential)
|
||||
// Overrides the login customer ID with the given one.
|
||||
->withLoginCustomerId($loginCustomerId)
|
||||
->build();
|
||||
}else{
|
||||
// Builds and returns the Google Ads client
|
||||
return (new GoogleAdsClientBuilder())
|
||||
// Sets the properties based on the default properties file
|
||||
->fromFile()
|
||||
// eUses the OAuth2 credentials crated above.
|
||||
->withOAuth2Credential($oAuth2Credential)
|
||||
// Overrides the login customer ID with the given one.
|
||||
->build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
174
app/service/GoogleAdsCampaignService.php
Normal file
174
app/service/GoogleAdsCampaignService.php
Normal file
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace app\service;
|
||||
|
||||
|
||||
use app\util\Helper;
|
||||
use app\util\ArgumentNames;
|
||||
use app\util\ArgumentParser;
|
||||
use Google\Ads\GoogleAds\Lib\V18\GoogleAdsClient;
|
||||
use Google\Ads\GoogleAds\Lib\V18\GoogleAdsClientBuilder;
|
||||
use Google\Ads\GoogleAds\Lib\V18\GoogleAdsException;
|
||||
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
|
||||
use Google\Ads\GoogleAds\V18\Common\ManualCpc;
|
||||
use Google\Ads\GoogleAds\V18\Enums\AdvertisingChannelTypeEnum\AdvertisingChannelType;
|
||||
use Google\Ads\GoogleAds\V18\Enums\BudgetDeliveryMethodEnum\BudgetDeliveryMethod;
|
||||
use Google\Ads\GoogleAds\V18\Enums\CampaignStatusEnum\CampaignStatus;
|
||||
use Google\Ads\GoogleAds\V18\Errors\GoogleAdsError;
|
||||
use Google\Ads\GoogleAds\V18\Resources\Campaign;
|
||||
use Google\Ads\GoogleAds\V18\Resources\Campaign\NetworkSettings;
|
||||
use Google\Ads\GoogleAds\V18\Resources\CampaignBudget;
|
||||
use Google\Ads\GoogleAds\V18\Services\CampaignBudgetOperation;
|
||||
use Google\Ads\GoogleAds\V18\Services\CampaignOperation;
|
||||
use Google\Ads\GoogleAds\V18\Services\MutateCampaignsRequest;
|
||||
use Google\Ads\GoogleAds\V18\Services\MutateCampaignBudgetsRequest;
|
||||
use Google\ApiCore\ApiException;
|
||||
|
||||
class GoogleAdsCampaignService
|
||||
{
|
||||
private $googleAdsClient;
|
||||
private $customerId;
|
||||
private const NUMBER_OF_CAMPAIGNS_TO_ADD = 1;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->customerId = getenv('GOOGLE_ADS_CUSTOMER_ID');
|
||||
|
||||
// OAuth2 Token Authentication
|
||||
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
|
||||
|
||||
// Google Ads Client initialization
|
||||
$this->googleAdsClient = (new GoogleAdsClientBuilder())
|
||||
->fromFile()
|
||||
->withOAuth2Credential($oAuth2Credential)
|
||||
->build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs the example.
|
||||
*
|
||||
* @param int $customerId the customer ID
|
||||
* @param $options
|
||||
* @return mixed
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function runAddCampaign(int $customerId, $options): mixed
|
||||
{
|
||||
$googleAdsClient = $this->googleAdsClient;
|
||||
// Creates a single shared budget to be used by the campaigns added below.
|
||||
$budgetResourceName = self::addCampaignBudget($googleAdsClient, $customerId,$options);
|
||||
|
||||
// Configures the campaign network options.
|
||||
$networkSettings = new NetworkSettings([
|
||||
'target_google_search' => true,
|
||||
'target_search_network' => true,
|
||||
// Enables Display Expansion on Search campaigns. See
|
||||
// https://support.google.com/google-ads/answer/7193800 to learn more.
|
||||
'target_content_network' => true,
|
||||
'target_partner_search_network' => false
|
||||
]);
|
||||
|
||||
$campaignOperations = [];
|
||||
for ($i = 0; $i < self::NUMBER_OF_CAMPAIGNS_TO_ADD; $i++) {
|
||||
// Creates a campaign.
|
||||
// [START add_campaigns_1]
|
||||
$campaign = new Campaign([
|
||||
// 'name' => 'Interplanetary Cruise #' . Helper::getPrintableDatetime(),
|
||||
'name' => $options['campaign_name'].rand(10,99).' #'. Helper::getPrintableDatetime(),
|
||||
'advertising_channel_type' => AdvertisingChannelType::SEARCH,
|
||||
// Recommendation: Set the campaign to PAUSED when creating it to prevent
|
||||
// the ads from immediately serving. Set to ENABLED once you've added
|
||||
// targeting and the ads are ready to serve.
|
||||
'status' => CampaignStatus::PAUSED,
|
||||
// Sets the bidding strategy and budget.
|
||||
'manual_cpc' => new ManualCpc(),
|
||||
'campaign_budget' => $budgetResourceName,
|
||||
// Adds the network settings configured above.
|
||||
'network_settings' => $networkSettings,
|
||||
// Optional: Sets the start and end dates.
|
||||
'start_date' => date('Ymd', strtotime('+1 day')),
|
||||
'end_date' => date('Ymd', strtotime('+1 month'))
|
||||
]);
|
||||
// [END add_campaigns_1]
|
||||
|
||||
// Creates a campaign operation.
|
||||
$campaignOperation = new CampaignOperation();
|
||||
$campaignOperation->setCreate($campaign);
|
||||
$campaignOperations[] = $campaignOperation;
|
||||
}
|
||||
|
||||
// Issues a mutate request to add campaigns.
|
||||
$campaignServiceClient = $googleAdsClient->getCampaignServiceClient();
|
||||
$response = $campaignServiceClient->mutateCampaigns(
|
||||
MutateCampaignsRequest::build($customerId, $campaignOperations)
|
||||
);
|
||||
// printf("Added %d campaigns:%s", $response->getResults()->count(), PHP_EOL);
|
||||
//
|
||||
foreach ($response->getResults() as $addedCampaign) {
|
||||
/** @var Campaign $addedCampaign */
|
||||
// print "{$addedCampaign->getResourceName()}" . PHP_EOL;
|
||||
$resourceNames[] = $addedCampaign->getResourceName();
|
||||
}
|
||||
return $resourceNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the example.
|
||||
*
|
||||
* @param int $customerId the customer ID
|
||||
* @param $options
|
||||
* @return mixed
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function runAddCampaignBudget(int $customerId, $options): mixed
|
||||
{
|
||||
if(!$customerId){
|
||||
$customerId = $this->customerId;
|
||||
}
|
||||
$googleAdsClient = $this->googleAdsClient;
|
||||
// Creates a single shared budget to be used by the campaigns added below.
|
||||
$budgetResourceName = self::addCampaignBudget($googleAdsClient, $customerId,$options);
|
||||
|
||||
return $budgetResourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new campaign budget in the specified client account.
|
||||
*
|
||||
* @param GoogleAdsClient $googleAdsClient the Google Ads API client
|
||||
* @param int $customerId the customer ID
|
||||
* @return string the resource name of the newly created budget
|
||||
* @throws ApiException
|
||||
*/
|
||||
// [START add_campaigns]
|
||||
private static function addCampaignBudget(GoogleAdsClient $googleAdsClient, int $customerId,$options)
|
||||
{
|
||||
|
||||
// Creates a campaign budget.
|
||||
$budget = new CampaignBudget([
|
||||
// 'name' => 'Interplanetary Cruise Budget #' . Helper::getPrintableDatetime(),
|
||||
'name' => $options['name'].rand(10,99).' #' . Helper::getPrintableDatetime(),
|
||||
// 'delivery_method' => BudgetDeliveryMethod::STANDARD,
|
||||
'amount_micros' => $options['amount'] * 1000000
|
||||
]);
|
||||
|
||||
// Creates a campaign budget operation.
|
||||
$campaignBudgetOperation = new CampaignBudgetOperation();
|
||||
$campaignBudgetOperation->setCreate($budget);
|
||||
|
||||
// Issues a mutate request.
|
||||
$campaignBudgetServiceClient = $googleAdsClient->getCampaignBudgetServiceClient();
|
||||
$response = $campaignBudgetServiceClient->mutateCampaignBudgets(
|
||||
MutateCampaignBudgetsRequest::build($customerId, [$campaignBudgetOperation])
|
||||
);
|
||||
|
||||
/** @var CampaignBudget $addedBudget */
|
||||
$addedBudget = $response->getResults()[0];
|
||||
// printf("Added budget named '%s'%s", $addedBudget->getResourceName(), PHP_EOL);
|
||||
|
||||
return $addedBudget->getResourceName();
|
||||
}
|
||||
// [END add_campaigns]
|
||||
|
||||
}
|
@ -29,7 +29,13 @@
|
||||
"monolog/monolog": "^2.0",
|
||||
"topthink/think-orm": "^3.0",
|
||||
"doctrine/dbal": "^3.9",
|
||||
"googleads/google-ads-php": "^25.0"
|
||||
"googleads/google-ads-php": "^25.0",
|
||||
"vlucas/phpdotenv": "^5.6",
|
||||
"guzzlehttp/guzzle": "^7.9",
|
||||
"webman/auto-route": "^1.0",
|
||||
"psr/container": "^1.1.1",
|
||||
"php-di/php-di": "^6.3",
|
||||
"doctrine/annotations": "^1.14"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-event": "For better performance. "
|
||||
@ -51,7 +57,10 @@
|
||||
],
|
||||
"pre-package-uninstall": [
|
||||
"support\\Plugin::uninstall"
|
||||
]
|
||||
],
|
||||
"remove-google-ads-api-version-support": [
|
||||
"Google\\Ads\\GoogleAds\\Util\\ApiVersionSupport::remove"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
|
778
composer.lock
generated
778
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "23def4d7784269b1c34d21751c7ddfb8",
|
||||
"content-hash": "cd1e2d3cc16ecbd085307c7d5d1f5c77",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
@ -50,6 +50,82 @@
|
||||
],
|
||||
"time": "2023-11-29T23:19:16+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/annotations",
|
||||
"version": "1.14.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/annotations.git",
|
||||
"reference": "253dca476f70808a5aeed3a47cc2cc88c5cab915"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/doctrine/annotations/zipball/253dca476f70808a5aeed3a47cc2cc88c5cab915",
|
||||
"reference": "253dca476f70808a5aeed3a47cc2cc88c5cab915",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"doctrine/lexer": "^1 || ^2",
|
||||
"ext-tokenizer": "*",
|
||||
"php": "^7.1 || ^8.0",
|
||||
"psr/cache": "^1 || ^2 || ^3"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/cache": "^1.11 || ^2.0",
|
||||
"doctrine/coding-standard": "^9 || ^12",
|
||||
"phpstan/phpstan": "~1.4.10 || ^1.10.28",
|
||||
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
|
||||
"symfony/cache": "^4.4 || ^5.4 || ^6.4 || ^7",
|
||||
"vimeo/psalm": "^4.30 || ^5.14"
|
||||
},
|
||||
"suggest": {
|
||||
"php": "PHP 8.0 or higher comes with attributes, a native replacement for annotations"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Guilherme Blanco",
|
||||
"email": "guilhermeblanco@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Roman Borschel",
|
||||
"email": "roman@code-factory.org"
|
||||
},
|
||||
{
|
||||
"name": "Benjamin Eberlei",
|
||||
"email": "kontakt@beberlei.de"
|
||||
},
|
||||
{
|
||||
"name": "Jonathan Wage",
|
||||
"email": "jonwage@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Johannes Schmitt",
|
||||
"email": "schmittjoh@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "Docblock Annotations Parser",
|
||||
"homepage": "https://www.doctrine-project.org/projects/annotations.html",
|
||||
"keywords": [
|
||||
"annotations",
|
||||
"docblock",
|
||||
"parser"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/doctrine/annotations/issues",
|
||||
"source": "https://github.com/doctrine/annotations/tree/1.14.4"
|
||||
},
|
||||
"time": "2024-09-05T10:15:52+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/cache",
|
||||
"version": "2.2.0",
|
||||
@ -310,6 +386,84 @@
|
||||
],
|
||||
"time": "2024-05-22T20:47:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/lexer",
|
||||
"version": "2.1.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/lexer.git",
|
||||
"reference": "861c870e8b75f7c8f69c146c7f89cc1c0f1b49b6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/doctrine/lexer/zipball/861c870e8b75f7c8f69c146c7f89cc1c0f1b49b6",
|
||||
"reference": "861c870e8b75f7c8f69c146c7f89cc1c0f1b49b6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"doctrine/deprecations": "^1.0",
|
||||
"php": "^7.1 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/coding-standard": "^9 || ^12",
|
||||
"phpstan/phpstan": "^1.3",
|
||||
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.6",
|
||||
"psalm/plugin-phpunit": "^0.18.3",
|
||||
"vimeo/psalm": "^4.11 || ^5.21"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Common\\Lexer\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Guilherme Blanco",
|
||||
"email": "guilhermeblanco@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Roman Borschel",
|
||||
"email": "roman@code-factory.org"
|
||||
},
|
||||
{
|
||||
"name": "Johannes Schmitt",
|
||||
"email": "schmittjoh@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.",
|
||||
"homepage": "https://www.doctrine-project.org/projects/lexer.html",
|
||||
"keywords": [
|
||||
"annotations",
|
||||
"docblock",
|
||||
"lexer",
|
||||
"parser",
|
||||
"php"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/doctrine/lexer/issues",
|
||||
"source": "https://github.com/doctrine/lexer/tree/2.1.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://www.doctrine-project.org/sponsorship.html",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://www.patreon.com/phpdoctrine",
|
||||
"type": "patreon"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Flexer",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-02-05T11:35:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "firebase/php-jwt",
|
||||
"version": "v6.10.2",
|
||||
@ -667,6 +821,48 @@
|
||||
"homepage": "https://github.com/googleads/google-ads-php",
|
||||
"time": "2024-10-18T08:01:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "graham-campbell/result-type",
|
||||
"version": "v1.1.3",
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://mirrors.cloud.tencent.com/repository/composer/graham-campbell/result-type/v1.1.3/graham-campbell-result-type-v1.1.3.zip",
|
||||
"reference": "3ba905c11371512af9d9bdd27d99b782216b6945",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"phpoption/phpoption": "^1.9.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GrahamCampbell\\ResultType\\": "src/"
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
}
|
||||
],
|
||||
"description": "An Implementation Of The Result Type",
|
||||
"keywords": [
|
||||
"Graham Campbell",
|
||||
"GrahamCampbell",
|
||||
"Result Type",
|
||||
"Result-Type",
|
||||
"result"
|
||||
],
|
||||
"time": "2024-07-20T21:45:45+00:00"
|
||||
},
|
||||
{
|
||||
"name": "grpc/grpc",
|
||||
"version": "1.57.0",
|
||||
@ -955,6 +1151,67 @@
|
||||
],
|
||||
"time": "2024-07-18T11:15:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/serializable-closure",
|
||||
"version": "v1.3.7",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/serializable-closure.git",
|
||||
"reference": "4f48ade902b94323ca3be7646db16209ec76be3d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/4f48ade902b94323ca3be7646db16209ec76be3d",
|
||||
"reference": "4f48ade902b94323ca3be7646db16209ec76be3d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.3|^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/support": "^8.0|^9.0|^10.0|^11.0",
|
||||
"nesbot/carbon": "^2.61|^3.0",
|
||||
"pestphp/pest": "^1.21.3",
|
||||
"phpstan/phpstan": "^1.8.2",
|
||||
"symfony/var-dumper": "^5.4.11|^6.2.0|^7.0.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Laravel\\SerializableClosure\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
},
|
||||
{
|
||||
"name": "Nuno Maduro",
|
||||
"email": "nuno@laravel.com"
|
||||
}
|
||||
],
|
||||
"description": "Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.",
|
||||
"keywords": [
|
||||
"closure",
|
||||
"laravel",
|
||||
"serializable"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/serializable-closure/issues",
|
||||
"source": "https://github.com/laravel/serializable-closure"
|
||||
},
|
||||
"time": "2024-11-14T18:34:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "monolog/monolog",
|
||||
"version": "2.10.0",
|
||||
@ -1077,6 +1334,234 @@
|
||||
],
|
||||
"time": "2018-02-13T20:26:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "php-di/invoker",
|
||||
"version": "2.3.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHP-DI/Invoker.git",
|
||||
"reference": "33234b32dafa8eb69202f950a1fc92055ed76a86"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/33234b32dafa8eb69202f950a1fc92055ed76a86",
|
||||
"reference": "33234b32dafa8eb69202f950a1fc92055ed76a86",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.3",
|
||||
"psr/container": "^1.0|^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"athletic/athletic": "~0.1.8",
|
||||
"mnapoli/hard-mode": "~0.3.0",
|
||||
"phpunit/phpunit": "^9.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Invoker\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "Generic and extensible callable invoker",
|
||||
"homepage": "https://github.com/PHP-DI/Invoker",
|
||||
"keywords": [
|
||||
"callable",
|
||||
"dependency",
|
||||
"dependency-injection",
|
||||
"injection",
|
||||
"invoke",
|
||||
"invoker"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/PHP-DI/Invoker/issues",
|
||||
"source": "https://github.com/PHP-DI/Invoker/tree/2.3.4"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/mnapoli",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2023-09-08T09:24:21+00:00"
|
||||
},
|
||||
{
|
||||
"name": "php-di/php-di",
|
||||
"version": "6.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHP-DI/PHP-DI.git",
|
||||
"reference": "ae0f1b3b03d8b29dff81747063cbfd6276246cc4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/ae0f1b3b03d8b29dff81747063cbfd6276246cc4",
|
||||
"reference": "ae0f1b3b03d8b29dff81747063cbfd6276246cc4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"laravel/serializable-closure": "^1.0",
|
||||
"php": ">=7.4.0",
|
||||
"php-di/invoker": "^2.0",
|
||||
"php-di/phpdoc-reader": "^2.0.1",
|
||||
"psr/container": "^1.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/container-implementation": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/annotations": "~1.10",
|
||||
"friendsofphp/php-cs-fixer": "^2.4",
|
||||
"mnapoli/phpunit-easymock": "^1.2",
|
||||
"ocramius/proxy-manager": "^2.11.2",
|
||||
"phpstan/phpstan": "^0.12",
|
||||
"phpunit/phpunit": "^9.5"
|
||||
},
|
||||
"suggest": {
|
||||
"doctrine/annotations": "Install it if you want to use annotations (version ~1.2)",
|
||||
"ocramius/proxy-manager": "Install it if you want to use lazy injection (version ~2.0)"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/functions.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"DI\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "The dependency injection container for humans",
|
||||
"homepage": "https://php-di.org/",
|
||||
"keywords": [
|
||||
"PSR-11",
|
||||
"container",
|
||||
"container-interop",
|
||||
"dependency injection",
|
||||
"di",
|
||||
"ioc",
|
||||
"psr11"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/PHP-DI/PHP-DI/issues",
|
||||
"source": "https://github.com/PHP-DI/PHP-DI/tree/6.4.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/mnapoli",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/php-di/php-di",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-04-09T16:46:38+00:00"
|
||||
},
|
||||
{
|
||||
"name": "php-di/phpdoc-reader",
|
||||
"version": "2.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHP-DI/PhpDocReader.git",
|
||||
"reference": "66daff34cbd2627740ffec9469ffbac9f8c8185c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHP-DI/PhpDocReader/zipball/66daff34cbd2627740ffec9469ffbac9f8c8185c",
|
||||
"reference": "66daff34cbd2627740ffec9469ffbac9f8c8185c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"mnapoli/hard-mode": "~0.3.0",
|
||||
"phpunit/phpunit": "^8.5|^9.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpDocReader\\": "src/PhpDocReader"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules as PHP)",
|
||||
"keywords": [
|
||||
"phpdoc",
|
||||
"reflection"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/PHP-DI/PhpDocReader/issues",
|
||||
"source": "https://github.com/PHP-DI/PhpDocReader/tree/2.2.1"
|
||||
},
|
||||
"time": "2020-10-12T12:39:22+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoption/phpoption",
|
||||
"version": "1.9.3",
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://mirrors.cloud.tencent.com/repository/composer/phpoption/phpoption/1.9.3/phpoption-phpoption-1.9.3.zip",
|
||||
"reference": "e3fac8b24f56113f7cb96af14958c0dd16330f54",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-master": "1.9-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpOption\\": "src/PhpOption/"
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Johannes M. Schmitt",
|
||||
"email": "schmittjoh@gmail.com",
|
||||
"homepage": "https://github.com/schmittjoh"
|
||||
},
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
}
|
||||
],
|
||||
"description": "Option Type for PHP",
|
||||
"keywords": [
|
||||
"language",
|
||||
"option",
|
||||
"php",
|
||||
"type"
|
||||
],
|
||||
"time": "2024-07-20T21:41:07+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/cache",
|
||||
"version": "3.0.0",
|
||||
@ -1119,27 +1604,28 @@
|
||||
},
|
||||
{
|
||||
"name": "psr/container",
|
||||
"version": "2.0.2",
|
||||
"version": "1.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/container.git",
|
||||
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://mirrors.cloud.tencent.com/repository/composer/psr/container/2.0.2/psr-container-2.0.2.zip",
|
||||
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963",
|
||||
"url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea",
|
||||
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Container\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
@ -1158,7 +1644,11 @@
|
||||
"container-interop",
|
||||
"psr"
|
||||
],
|
||||
"time": "2021-11-05T16:47:00+00:00"
|
||||
"support": {
|
||||
"issues": "https://github.com/php-fig/container/issues",
|
||||
"source": "https://github.com/php-fig/container/tree/1.1.2"
|
||||
},
|
||||
"time": "2021-11-05T16:50:12+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-client",
|
||||
@ -1595,6 +2085,176 @@
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2024-09-25T14:20:29+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"version": "v1.31.0",
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://mirrors.cloud.tencent.com/repository/composer/symfony/polyfill-ctype/v1.31.0/symfony-polyfill-ctype-v1.31.0.zip",
|
||||
"reference": "a3cc8b044a6ea513310cbd48ef7333b384945638",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"provide": {
|
||||
"ext-ctype": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-ctype": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/polyfill",
|
||||
"name": "symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Ctype\\": ""
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gert de Pagter",
|
||||
"email": "BackEndTea@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for ctype functions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"ctype",
|
||||
"polyfill",
|
||||
"portable"
|
||||
],
|
||||
"time": "2024-09-09T11:45:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.31.0",
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://mirrors.cloud.tencent.com/repository/composer/symfony/polyfill-mbstring/v1.31.0/symfony-polyfill-mbstring-v1.31.0.zip",
|
||||
"reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"provide": {
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/polyfill",
|
||||
"name": "symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"mbstring",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"time": "2024-09-09T11:45:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-php80",
|
||||
"version": "v1.31.0",
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://mirrors.cloud.tencent.com/repository/composer/symfony/polyfill-php80/v1.31.0/symfony-polyfill-php80-v1.31.0.zip",
|
||||
"reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/polyfill",
|
||||
"name": "symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Php80\\": ""
|
||||
},
|
||||
"classmap": [
|
||||
"Resources/stubs"
|
||||
]
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ion Bazan",
|
||||
"email": "ion.bazan@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"time": "2024-09-09T11:45:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "topthink/think-helper",
|
||||
"version": "v3.1.10",
|
||||
@ -1679,6 +2339,100 @@
|
||||
],
|
||||
"time": "2024-12-10T13:38:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vlucas/phpdotenv",
|
||||
"version": "v5.6.1",
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://mirrors.cloud.tencent.com/repository/composer/vlucas/phpdotenv/v5.6.1/vlucas-phpdotenv-v5.6.1.zip",
|
||||
"reference": "a59a13791077fe3d44f90e7133eb68e7d22eaff2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-pcre": "*",
|
||||
"graham-campbell/result-type": "^1.1.3",
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"phpoption/phpoption": "^1.9.3",
|
||||
"symfony/polyfill-ctype": "^1.24",
|
||||
"symfony/polyfill-mbstring": "^1.24",
|
||||
"symfony/polyfill-php80": "^1.24"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"ext-filter": "*",
|
||||
"phpunit/phpunit": "^8.5.34 || ^9.6.13 || ^10.4.2"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-filter": "Required to use the boolean validator."
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-master": "5.6-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dotenv\\": "src/"
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
},
|
||||
{
|
||||
"name": "Vance Lucas",
|
||||
"email": "vance@vancelucas.com",
|
||||
"homepage": "https://github.com/vlucas"
|
||||
}
|
||||
],
|
||||
"description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
|
||||
"keywords": [
|
||||
"dotenv",
|
||||
"env",
|
||||
"environment"
|
||||
],
|
||||
"time": "2024-07-20T21:52:34+00:00"
|
||||
},
|
||||
{
|
||||
"name": "webman/auto-route",
|
||||
"version": "v1.0.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/webman-php/auto-route.git",
|
||||
"reference": "ae7410ed2db5a080a0cf072f501123a6f537aeac"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/webman-php/auto-route/zipball/ae7410ed2db5a080a0cf072f501123a6f537aeac",
|
||||
"reference": "ae7410ed2db5a080a0cf072f501123a6f537aeac",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Webman\\AutoRoute\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/webman-php/auto-route/issues",
|
||||
"source": "https://github.com/webman-php/auto-route/tree/v1.0.5"
|
||||
},
|
||||
"time": "2022-08-18T12:14:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "workerman/webman-framework",
|
||||
"version": "v1.6.8",
|
||||
@ -1775,12 +2529,12 @@
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "dev",
|
||||
"stability-flags": [],
|
||||
"stability-flags": {},
|
||||
"prefer-stable": true,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"platform-dev": {},
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
|
@ -12,4 +12,10 @@
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
return new Webman\Container;
|
||||
//return new Webman\Container;
|
||||
|
||||
$builder = new \DI\ContainerBuilder();
|
||||
$builder->addDefinitions(config('dependence', []));
|
||||
$builder->useAutowiring(true);
|
||||
$builder->useAnnotations(true);
|
||||
return $builder->build();
|
@ -1,5 +1,62 @@
|
||||
[GOOGLE_ADS]
|
||||
developer_token = "C5wRcPCLwubnNgOEqweLBA"
|
||||
client_id = "117429539543-t73vtg7v1vag5b2dg68qaaaj00gmacjs.apps.googleusercontent.com"
|
||||
client_secret = "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"
|
||||
refresh_token = "1//0eAC5wgBctJo3CgYIARAAGA4SNwF-L9Ir8lepCIkpDPvGHltj_1afFbW7tpb61OdbPdrvsjIVEbvMZnkPTi2f4WtgbtH97eX2iXE"
|
||||
; Required some config parameters, which can be found at:
|
||||
; https://developers.google.com/google-ads/api/docs/first-call/overview#config
|
||||
developerToken = "C5wRcPCLwubnNgOEqweLBA"
|
||||
|
||||
|
||||
; The configuration setting name for a flag that specifies whether to use the Google
|
||||
; Cloud Organization of your Google Cloud project instead of developer token to
|
||||
; determine your Google Ads API access levels.
|
||||
; useCloudOrgForApiAccess = false
|
||||
|
||||
; Required for manager accounts only: Specify the login customer ID used to authenticate API calls.
|
||||
; This will be the customer ID of the authenticated manager account. You can also specify this later
|
||||
; in code if your application uses multiple manager account + OAuth pairs. It should be set
|
||||
; without dashes, for example: 1234567890 instead of 123-456-7890.
|
||||
; loginCustomerId = "INSERT_LOGIN_CUSTOMER_ID_HERE"
|
||||
loginCustomerId = 1509096882
|
||||
; This header is only required for methods that update the resources of an entity when permissioned
|
||||
; via Linked Accounts in the Google Ads UI (AccountLink resource in the Google Ads API). Set this
|
||||
; value to the customer ID of the data provider that updates the resources of the specified
|
||||
; customer ID. It should be set without dashes, for example: 1234567890 instead of 123-456-7890.
|
||||
; Read https://support.google.com/google-ads/answer/7365001 to learn more about Linked Accounts.
|
||||
; linkedCustomerId = "INSERT_LINKED_CUSTOMER_ID_HERE"
|
||||
|
||||
; Optional additional settings.
|
||||
; endpoint = "https://googleads.googleapis.com/"
|
||||
|
||||
[OAUTH2]
|
||||
; Required OAuth2 credentials. Uncomment and fill in the values for the
|
||||
; appropriate flow based on your use case.
|
||||
|
||||
; For installed application flow.
|
||||
clientId = "117429539543-t73vtg7v1vag5b2dg68qaaaj00gmacjs.apps.googleusercontent.com"
|
||||
clientSecret = "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"
|
||||
refreshToken = "1//0ei7JnUPbgXopCgYIARAAGA4SNwF-L9Irma-BXlnDqEtrklnBXNK13e915TyQsEXbinSW3v0ZsKYB7C7-bYe2xG7osPLQ5xzeqo8"
|
||||
|
||||
; For service account flow.
|
||||
; jsonKeyFilePath = "INSERT_ABSOLUTE_PATH_TO_OAUTH2_JSON_KEY_FILE_HERE"
|
||||
; scopes = "https://www.googleapis.com/auth/adwords"
|
||||
; impersonatedEmail = "INSERT_EMAIL_OF_ACCOUNT_TO_IMPERSONATE_HERE"
|
||||
|
||||
[LOGGING]
|
||||
; Optional logging settings.
|
||||
; logFilePath = "path/to/your/file.log"
|
||||
; logLevel = "INFO"
|
||||
logFilePath = "runtime/logs/google_ads.log"
|
||||
logLevel = "INFO"
|
||||
|
||||
[CONNECTION]
|
||||
; Optional proxy settings to be used by requests.
|
||||
; If you don't have username and password, just specify host and port.
|
||||
; proxy = "protocol://user:pass@host:port"
|
||||
|
||||
; Optional transport settings.
|
||||
; By default, "grpc" is used if available otherwise "rest".
|
||||
; transport = "grpc"
|
||||
transport = "rest"
|
||||
; Optional gRPC channel settings.
|
||||
; Whether the gRPC channel to use is secure or not. Insecure gRPC channels should not be used in
|
||||
; production because they do not use encryption or authentication, they should only be used for
|
||||
; testing. By default, it is set to true (secure).
|
||||
; grpcChannelIsSecure = true
|
||||
|
@ -12,10 +12,41 @@
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
use app\controller\IndexController;
|
||||
use app\controller\GoogleAdsController;
|
||||
use Webman\Route;
|
||||
|
||||
|
||||
|
||||
//Route::group('/googleads', function () {
|
||||
// Route::group('/campaign', function () {
|
||||
// Route::post('/create', 'GoogleAdsController@createCampaign');
|
||||
// });
|
||||
// Route::group('/campaign_budget', function () {
|
||||
// Route::post('/create', 'GoogleAdsController@createCampaignBudget');
|
||||
// });
|
||||
//});
|
||||
|
||||
Route::group('/googleads', function () {
|
||||
Route::group('/campaign', function () {
|
||||
Route::post('/create', [GoogleAdsController::class, 'createCampaign']);
|
||||
});
|
||||
Route::group('/campaign_budget', function () {
|
||||
Route::post('/create', [GoogleAdsController::class, 'createCampaignBudget']);
|
||||
});
|
||||
Route::group('/account_link', function () {
|
||||
Route::post('/create', [GoogleAdsController::class, 'createLinkManagerToClient']);
|
||||
});
|
||||
Route::group('/account_link', function () {
|
||||
Route::post('/list', [GoogleAdsController::class, 'accessibleCustomers']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user