Позвольте пользователю выбрать, к какому представлению он хочет получить доступ, затем запустите ваш код для этого представления. Этот код покажет вам, как составить список просмотров, к которым у пользователя есть доступ.
<code>/**
* Note: This code assumes you have an authorized Analytics service object.
* See the Account Summaries Developer Guide for details.
*/
/**
* Example #1:
* Requests a list of all account summaries for the authorized user.
*/
try {
$accounts = $analytics->management_accountSummaries
->listManagementAccountSummaries();
} catch (apiServiceException $e) {
print 'There was an Analytics API service error '
. $e->getCode() . ':' . $e->getMessage();
} catch (apiException $e) {
print 'There was a general API error '
. $e->getCode() . ':' . $e->getMessage();
}
/**
* Example #2:
* The results of the list method are stored in the accounts object.
* The following code shows how to iterate through them.
*/
foreach ($accounts->getItems() as $account) {
$html = <<<HTML
<pre>
Account id = {$account->getId()}
Account kind = {$account->getKind()}
Account name = {$account->getName()}
HTML;
// Iterate through each Property.
foreach ($account->getWebProperties() as $property) {
$html .= <<<HTML
Property id = {$property->getId()}
Property kind = {$property->getKind()}
Property name = {$property->getName()}
Internal property id = {$property->getInternalWebPropertyId()}
Property level = {$property->getLevel()}
Property URL = {$property->getWebsiteUrl()}
HTML;
// Iterate through each view (profile).
foreach ($property->getProfiles() as $profile) {
$html .= <<<HTML
Profile id = {$profile->getId()}
Profile kind = {$profile->getKind()}
Profile name = {$profile->getName()}
Profile type = {$profile->getType()}
HTML;
}
}
$html .= '
'; печатать $ html; }