examples/AdWords/LaravelSampleApp/app/Http/Controllers/AdWordsApiController.php
public function getCampaignsAction(
        Request $request,
        FetchAuthTokenInterface $oAuth2Credential,
        AdWordsServices $adWordsServices,
        AdWordsSessionBuilder $adWordsSessionBuilder
    ) {
        if ($request->method() === 'POST') {
            // Always select at least the "Id" field.
            $selectedFields = array_values(
                ['id' => 'Id'] + $request->except(
                    ['_token', 'clientCustomerId', 'entriesPerPage']
                )
            );
            $clientCustomerId = $request->input('clientCustomerId');
            $entriesPerPage = $request->input('entriesPerPage');

            // Construct an API session configured from a properties file and
            // the OAuth2 credentials above.
            $session =
                $adWordsSessionBuilder->fromFile(config('app.adsapi_php_path'))
                    ->withOAuth2Credential($oAuth2Credential)
                    ->withClientCustomerId($clientCustomerId)
                    ->build();

            $request->session()->put('selectedFields', $selectedFields);
            $request->session()->put('entriesPerPage', $entriesPerPage);
            $request->session()->put('session', $session);
        } else {
            $selectedFields = $request->session()->get('selectedFields');
            $entriesPerPage = $request->session()->get('entriesPerPage');
            $session = $request->session()->get('session');
        }

        $pageNo = $request->input('page') ?: 1;
        $collection = self::fetchCampaigns(
            $request,
            $adWordsServices->get($session, CampaignService::class),
            $selectedFields,
            $entriesPerPage,
            $pageNo
        );

        // Create a length aware paginator to supply campaigns for the view,
        // based on the specified number of entries per page.
        $campaigns = new LengthAwarePaginator(
            $collection,
            $request->session()->get('totalNumEntries'),
            $entriesPerPage,
            $pageNo,
            ['path' => url('get-campaigns')]
        );

        return view('campaigns', compact('campaigns', 'selectedFields'));
    }
public function getCampaignsAction(
        Request $request,
        FetchAuthTokenInterface $oAuth2Credential,
        AdWordsServices $adWordsServices,
        AdWordsSessionBuilder $adWordsSessionBuilder
    ) {
        if ($request->method() === 'POST') {
            // Always select at least the "Id" field.
            $selectedFields = array_values(
                ['id' => 'Id'] + $request->except(
                    ['_token', 'clientCustomerId', 'entriesPerPage']
                )
            );
            $clientCustomerId = $request->input('clientCustomerId');
            $entriesPerPage = $request->input('entriesPerPage');

            // Construct an API session configured from a properties file and
            // the OAuth2 credentials above.
            $session =
                $adWordsSessionBuilder->fromFile(config('app.adsapi_php_path'))
                    ->withOAuth2Credential($oAuth2Credential)
                    ->withClientCustomerId($clientCustomerId)
                    ->build();

            $request->session()->put('selectedFields', $selectedFields);
            $request->session()->put('entriesPerPage', $entriesPerPage);
            $request->session()->put('session', $session);
        } else {
            $selectedFields = $request->session()->get('selectedFields');
            $entriesPerPage = $request->session()->get('entriesPerPage');
            $session = $request->session()->get('session');
        }

        $pageNo = $request->input('page') ?: 1;
        $collection = self::fetchCampaigns(
            $request,
            $adWordsServices->get($session, CampaignService::class),
            $selectedFields,
            $entriesPerPage,
            $pageNo
        );

        // Create a length aware paginator to supply campaigns for the view,
        // based on the specified number of entries per page.
        $campaigns = new LengthAwarePaginator(
            $collection,
            $request->session()->get('totalNumEntries'),
            $entriesPerPage,
            $pageNo,
            ['path' => url('get-campaigns')]
        );

        return view('campaigns', compact('campaigns', 'selectedFields'));
    }
public function getCampaignsAction ( Request $ request , FetchAuthTokenInterface $ oAuth2Credential , AdWordsServices $ adWordsServices , AdWordsSessionBuilder $ adWordsSessionBuilder ) { if ( $ request -> method ( ) === 'POST' ) { // Always select at least the "Id" field. $ selectedFields = array_values ( [ 'id' => 'Id' ] + $ request -> except ( [ '_token' , 'clientCustomerId' , 'entriesPerPage' ] ) ) ; $ clientCustomerId = $ request -> input ( 'clientCustomerId' ) ; $ entriesPerPage = $ request -> input ( 'entriesPerPage' ) ; // Construct an API session configured from a properties file and // the OAuth2 credentials above. $ session = $ adWordsSessionBuilder -> fromFile ( config ( 'app.adsapi_php_path' ) ) -> withOAuth2Credential ( $ oAuth2Credential ) -> withClientCustomerId ( $ clientCustomerId ) -> build ( ) ; $ request -> session ( ) -> put ( 'selectedFields' , $ selectedFields ) ; $ request -> session ( ) -> put ( 'entriesPerPage' , $ entriesPerPage ) ; $ request -> session ( ) -> put ( 'session' , $ session ) ; } else { $ selectedFields = $ request -> session ( ) -> get ( 'selectedFields' ) ; $ entriesPerPage = $ request -> session ( ) -> get ( 'entriesPerPage' ) ; $ session = $ request -> session ( ) -> get ( 'session' ) ; } $ pageNo = $ request -> input ( 'page' ) ? : 1 ; $ collection = self :: fetchCampaigns ( $ request , $ adWordsServices -> get ( $ session , CampaignService :: class ) , $ selectedFields , $ entriesPerPage , $ pageNo ) ; // Create a length aware paginator to supply campaigns for the view, // based on the specified number of entries per page. $ campaigns = new LengthAwarePaginator ( $ collection , $ request -> session ( ) -> get ( 'totalNumEntries' ) , $ entriesPerPage , $ pageNo , [ 'path' => url ( 'get-campaigns' ) ] ) ; return view ( 'campaigns' , compact ( 'campaigns' , 'selectedFields' ) ) ; }
Controls a POST and GET request that is submitted from the "Get All
Campaigns" form.

@param Request $request
@param FetchAuthTokenInterface $oAuth2Credential
@param AdWordsServices $adWordsServices
@param AdWordsSessionBuilder $adWordsSessionBuilder
@return View
Controls a POST and GET request that is submitted from the Get All Campaigns form .