$parameters = ['access_type' => 'offline']; $driver = Socialite::driver('google')->with($parameters); $user = $driver->stateless()->user(); // dd($user); $accessToken = $user->token; $authorizationCode = $_GET['code'];
// $this->afterGoogleCallback($user,$authorizationCode,$accessToken); $clientid = config('values.Client_ID'); $clientSecret = config('values.Client_secret'); $developerToken = config('values.developer_token'); $redirect_uri = config('values.redirect_uri'); $refresh_token = config('values.google_refresh_token'); $array = [ 'authorizationCode' => $authorizationCode, 'grant_type' => 'authorization_code', 'access_token' => $accessToken, 'tokenCredentialUri' => 'https://oauth2.googleapis.com/token', 'clientId' => $clientid, 'clientSecret' => $clientSecret, 'redirectUri' => $redirect_uri, 'developerToken' => $developerToken, 'refreshToken' => $refresh_token, ]; try { $oauth2Credentials = new OAuth2($array); $oAuth2Credential = (new OAuth2TokenBuilder())->fromFile(public_path( 'google_ads_php.ini'))->build(); $googleAdsClient = (new GoogleAdsClientBuilder()) ->fromFile(public_path('google_ads_php.ini')) ->withOAuth2Credential($oAuth2Credential) ->build(); $this->runExample($googleAdsClient,$authorizationCode); } catch (Exception $e) { // Handle any exceptions that may occur during OAuth2 or API requests dd($e); } public static function runExample(GoogleAdsClient $googleAdsClient, $authorizationCode){ // dd($authorizationCode); $customerServiceClient = $googleAdsClient->getCustomerServiceClient(); // dd($customerServiceClient); // Create an array of optional arguments $optionalArgs = []; // Issues a request for listing all accessible customers. try { $accessibleCustomers = $customerServiceClient->listAccessibleCustomers(); } catch (Exception $e) { dd($e); } // Create an array to store account names $accountNames = []; // Iterates over all accessible customers' resource names. foreach ($accessibleCustomers->getResourceNames() as $resourceName) { // Extract the customer ID from the resource name. $parts = explode('/', $resourceName); $customerId = end($parts); $accountNames[]=$customerId; } dd($accountNames); // Dump the array containing account names. foreach ($accountNames as $id) { if ($id == 6444085743) { $query = "SELECT customer.id, customer.descriptive_name FROM customer"; $streamRequest = $googleAdsClient->getGoogleAdsServiceClient()->searchStream ($id, $query); foreach ($streamRequest->iterateAllElements() as $element) { // Extract data from each result element. $customerId = $element->getCustomer()->getId(); $descriptiveName = $element->getCustomer()->getDescriptiveName(); // Do something with the data, such as printing or storing it. // dd("Customer ID: $customerId, Descriptive Name: $descriptiveName"); $contas = self::getCustomerAccounts($googleAdsClient,$customerId); foreach ($contas as $account) { $accountId = $account->getClientCustomer(); $accountName = $account->getDescriptiveName(); // Do something with the account data, such as printing or storing it. dd("Customer ID: $customerId, Account ID: $accountId, Account Name: $accountName"); } } } } dd($accountNames); } public static function runExample(GoogleAdsClient $googleAdsClient, $authorizationCode){ // dd($authorizationCode); $customerServiceClient = $googleAdsClient->getCustomerServiceClient(); // dd($customerServiceClient); // Create an array of optional arguments $optionalArgs = []; // Issues a request for listing all accessible customers. try { $accessibleCustomers = $customerServiceClient->listAccessibleCustomers(); } catch (Exception $e) { dd($e); } // Create an array to store account names $accountNames = []; // Iterates over all accessible customers' resource names. foreach ($accessibleCustomers->getResourceNames() as $resourceName) { // Extract the customer ID from the resource name. $parts = explode('/', $resourceName); $customerId = end($parts); $accountNames[]=$customerId; } dd($accountNames); // Dump the array containing account names. foreach ($accountNames as $id) { if ($id == 6444085743) { $query = "SELECT customer.id, customer.descriptive_name FROM customer"; $streamRequest = $googleAdsClient->getGoogleAdsServiceClient()->searchStream ($id, $query); foreach ($streamRequest->iterateAllElements() as $element) { // Extract data from each result element. $customerId = $element->getCustomer()->getId(); $descriptiveName = $element->getCustomer()->getDescriptiveName(); // Do something with the data, such as printing or storing it. // dd("Customer ID: $customerId, Descriptive Name: $descriptiveName"); $contas = self::getCustomerAccounts($googleAdsClient,$customerId); foreach ($contas as $account) { $accountId = $account->getClientCustomer(); $accountName = $account->getDescriptiveName(); // Do something with the account data, such as printing or storing it. dd("Customer ID: $customerId, Account ID: $accountId, Account Name: $accountName"); } } } } dd($accountNames); } -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ Also find us on our blog: https://googleadsdeveloper.blogspot.com/ =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ You received this message because you are subscribed to the Google Groups "AdWords API and Google Ads API Forum" group. To post to this group, send email to adwords-api@googlegroups.com To unsubscribe from this group, send email to adwords-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/adwords-api?hl=en --- You received this message because you are subscribed to the Google Groups "Google Ads API and AdWords API Forum" group. To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/b917082c-9ade-4517-a577-47c93be249cbn%40googlegroups.com.