Class CampaignService does not exist

371 views
Skip to first unread message

Minas Gratas

unread,
Jan 9, 2017, 10:15:20 AM1/9/17
to AdWords API Forum
Hi,

So I am trying to get users consent and proceed getCampaigns with his user. I am getting his consents, but cannot fetch the information on his account. I am trying to implement this code here https://github.com/googleads/googleads-php-lib/wiki/API-access-on-behalf-of-your-clients-(web-flow) but I must be missing something because I am getting a Fatal Error below;

Fatal error: Uncaught exception 'ReflectionException' with message 'Class CampaignService does not exist' in /Applications/MAMP/htdocs/adwords/api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/AdWords/AdWordsServiceDescriptor.php on line 46

ReflectionException: Class CampaignService does not exist in /Applications/MAMP/htdocs/adwords/api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/AdWords/AdWordsServiceDescriptor.php on line 46

Can you help me find me issue here? I 

require_once 'api/vendor/autoload.php';
use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\Common\OAuth2TokenBuilder;
use Google\Auth\OAuth2;

session_start();
$oauth2 = new OAuth2([
    'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth',
    'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',
    'redirectUri' => '*****',
    'clientId' => '*****',
    'clientSecret' => '*****',
    'scope' => 'https://www.googleapis.com/auth/adwords'
]);

if (!isset($_GET['code'])) {
    // Create a 'state' token to prevent request forgery.
    // Store it in the session for later validation.
    $oauth2->setState(sha1(openssl_random_pseudo_bytes(1024)));
    $_SESSION['oauth2state'] = $oauth2->getState();

    // Redirect the user to the authorization URL.
    $config = [
        // Set to 'offline' if you require offline access.
        'access_type' => 'offline'
    ];
    header('Location: ' . $oauth2->buildFullAuthorizationUri($config));
    exit;
}
// Check given state against previously stored one to mitigate CSRF attack.
 elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
  unset($_SESSION['oauth2state']);
  exit('Invalid state.');
} else {

  $oauth2->setCode($_GET['code']);
  $authToken = $oauth2->fetchAuthToken();
  // Store the refresh token for your user in your local storage if you
  // requested offline access.
  $refreshToken = $authToken['refresh_token'];
    $session = (new AdWordsSessionBuilder())
        ->fromFile()
        ->withOAuth2Credential($oauth2)
        ->build();
    $adWordsServices = new AdWordsServices();
    $campaignService = $adWordsServices->get($session, 'CampaignService', 'v201603', 'cm');
}


Vishal Vinayak (Adwords API Team)

unread,
Jan 9, 2017, 4:16:05 PM1/9/17
to AdWords API Forum
Hi,

Since your issue is related to the PHP client library, I would recommend posting your issue here. Also, I can see that you are trying to use the v201603 version of the API which is now sunset. I would recommend using the latest version of the API i.e. v201609.

Regards,
Vishal, AdWords API Team
Reply all
Reply to author
Forward
0 new messages