예제 #1
0
 public function testGetAuthToken()
 {
     $user = new User();
     $user->setEmail($this->userSettings['email']);
     $user->setPassword($this->userSettings['password']);
     $user->setAuthToken($this->userSettings['authToken']);
     $authToken = $user->getAuthToken();
     $this->assertNotEmpty($authToken, 'Expected not empty auth token');
 }
/**
 * Runs the example.
 *
 * @param \AdWords\User $user the user to run the example with
 */
function getAccountHierarchyExample(\AdWords\User $user)
{
    $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false);
    $soapClientFactory->setServer('https://adwords-sandbox.google.com');
    // Get the service, which loads the required classes.
    /** @var \AdWords\mcm\v201109\ServicedAccountService $servicedAccountService */
    $servicedAccountService = $soapClientFactory->generateSoapClient('ServicedAccount');
    // Create selector.
    $selector = new \AdWords\mcm\v201109\ServicedAccountSelector();
    // To get the links paging must be disabled.
    $selector->enablePaging = false;
    // Make the get request.
    $graph = $servicedAccountService->get($selector);
    // Display serviced account graph.
    if (isset($graph->accounts)) {
        // Create map from customerId to parent and child links.
        $childLinks = array();
        $parentLinks = array();
        if (isset($graph->links)) {
            foreach ($graph->links as $link) {
                $childLinks[$link->managerId->id][] = $link;
                $parentLinks[$link->clientId->id][] = $link;
            }
        }
        // Create map from customerID to account, and find root account.
        $accounts = array();
        $rootAccount = null;
        foreach ($graph->accounts as $account) {
            $accounts[(string) $account->customerId] = $account;
            if (!array_key_exists((string) $account->customerId, $parentLinks)) {
                $rootAccount = $account;
            }
        }
        // The root account may not be returned in the sandbox.
        if (!isset($rootAccount)) {
            $rootAccount = new \AdWords\mcm\v201109\Account();
            $rootAccount->customerId = 0;
            $rootAccount->login = $user->GetEmail();
        }
        // Display account tree.
        print "(Customer Id, Account Name/Login, Link Status)\n";
        displayAccountTree($rootAccount, NULL, $accounts, $childLinks, 0);
    } else {
        print "No serviced accounts were found.\n";
    }
}