本文整理汇总了PHP中AdWordsUser::LogAll方法的典型用法代码示例。如果您正苦于以下问题:PHP AdWordsUser::LogAll方法的具体用法?PHP AdWordsUser::LogAll怎么用?PHP AdWordsUser::LogAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdWordsUser
的用法示例。
在下文中一共展示了AdWordsUser::LogAll方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: UseOAuth2Example
/**
* Runs the example.
* @param string $clientId the OAuth2 client ID
* @param string $clientSecret the OAuth2 client secret
*/
function UseOAuth2Example($clientId, $clientSecret)
{
// Set the OAuth2 client ID and secret.
$oauth2Info = array('client_id' => $clientId, 'client_secret' => $clientSecret);
// Create the AdWordsUser and set the OAuth2 info.
$user = new AdWordsUser();
$user->SetOAuth2Info($oauth2Info);
$user->LogAll();
// Get the authorization URL for the OAuth2 token.
// No redirect URL is being used since this is an installed application. A web
// application would pass in a redirect URL back to the application,
// ensuring it's one that has been configured in the API console.
// Passing true for the second parameter ($offline) will provide us a refresh
// token which can used be refresh the access token when it expires.
$authorizationUrl = $user->GetOAuth2AuthorizationUrl(NULL, TRUE);
// In a web application you would redirect the user to the authorization URL
// and after approving the token they would be redirected back to the
// redirect URL, with the URL parameter "code" added. For desktop
// or server applications, spawn a browser to the URL and then have the user
// enter the authorization code that is displayed.
printf("Log in to your AdWords account and open the following URL: %s\n", $authorizationUrl);
print 'After approving the token enter the authorization code here: ';
$stdin = fopen('php://stdin', 'r');
$code = trim(fgets($stdin));
fclose($stdin);
// Get the access token using the authorization code. Ensure you use the same
// redirect URL used when requesting authorization.
$user->GetOAuth2AccessToken($code, NULL);
// The access token expires but the refresh token obtained for offline use
// doesn't, and should be stored for later use.
$oauth2Info = $user->GetOAuth2Info();
print "OAuth2 authorization successful.\n";
print_r($oauth2Info);
// Get the number of campaigns in the account.
$campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);
$selector = new Selector();
$selector->fields = array('Id');
$selector->paging = new Paging(0, 0);
$page = $campaignService->get($selector);
// Display number of campaigns.
printf("Found %d campaigns.\n", $page->totalNumEntries);
}
示例2: UseOAuthExample
/**
* Runs the example.
*/
function UseOAuthExample()
{
// Set the OAuth consumer key and secret. Anonymous values can be used for
// testing, and real values can be obtained by registering your application:
// http://code.google.com/apis/accounts/docs/RegistrationForWebAppsAuto.html
$oauthInfo = array('oauth_consumer_key' => 'anonymous', 'oauth_consumer_secret' => 'anonymous');
// Create the AdWordsUser and set the OAuth info.
$user = new AdWordsUser();
$user->SetOAuthInfo($oauthInfo);
$user->LogAll();
// Request a new OAuth token. Web applications should pass in a callback URL
// to redirect the user to after authorizing the token.
$user->RequestOAuthToken();
// Get the authorization URL for the OAuth token.
$authorizationUrl = $user->GetOAuthAuthorizationUrl();
// In a web application you would redirect the user to the authorization URL
// and after approving the token they would be redirected back to the
// callback URL, with the URL parameter "oauth_verifier" added. For desktop
// or server applications, spawn a browser to the URL and then have the user
// enter the verification code that is displayed.
printf("Log in to your AdWords account and open the following URL: %s\n", $authorizationUrl);
print 'After approving the token enter the verification code here: ';
$stdin = fopen('php://stdin', 'r');
$verifier = trim(fgets($stdin));
fclose($stdin);
// Upgrade the authorized token.
$user->UpgradeOAuthToken($verifier);
// An upgraded token does not expire and should be stored and reused for
// every request to the API.
$oauthInfo = $user->GetOAuthInfo();
print "OAuth authorization successful.\n";
print_r($oauthInfo);
// Get the number of campaigns in the account.
$campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);
$selector = new Selector();
$selector->fields = array('Id');
$selector->paging = new Paging(0, 0);
$page = $campaignService->get($selector);
// Display number of campaigns.
printf("Found %d campaigns.\n", $page->totalNumEntries);
}
示例3: AdGroupAd
$adGroupAd = new AdGroupAd();
$adGroupAd->adGroupId = $adGroupId;
$adGroupAd->ad = $ad;
// Update the status.
$adGroupAd->status = 'PAUSED';
// Create operation.
$operation = new AdGroupAdOperation();
$operation->operand = $adGroupAd;
$operation->operator = 'SET';
$operations = array($operation);
// Make the mutate request.
$result = $adGroupAdService->mutate($operations);
// Display result.
$adGroupAd = $result->value[0];
printf("Ad of type '%s' with id '%s' has updated status '%s'.\n", $adGroupAd->ad->AdType, $adGroupAd->ad->id, $adGroupAd->status);
}
// Don't run the example if the file is being included.
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {
return;
}
try {
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$user = new AdWordsUser();
// Log every SOAP XML request and response.
$user->LogAll();
// Run the example.
PauseAdExample($user, $adGroupId, $adId);
} catch (Exception $e) {
printf("An error has occurred: %s\n", $e->getMessage());
}
示例4: createUser
private function createUser()
{
$user = new \AdWordsUser(null, $this->config->getDeveloperToken(), $this->config->getUserAgent(), null, null, $this->config->getOauth2Info());
$user->SetClientCustomerId($this->config->getClientCustomerId());
LoggerStreamWrapper::setLogger($this->logger);
$handler = LoggerStreamWrapper::register();
\Logger::LogToStream(\Logger::$SOAP_XML_LOG, $handler);
\Logger::LogToStream(\Logger::$REQUEST_INFO_LOG, $handler);
\Logger::LogToStream(\ReportUtils::$LOG_NAME, $handler);
// Log every SOAP XML request and response.
$user->LogAll();
return $user;
}