A service error occurred: %s
An client error occurred: %s
You need to set \$OAUTH2_CLIENT_ID and
\$OAUTH2_CLIENT_ID before proceeding.
END;
} else {
// If the user hasn't authorized the app, initiate the OAuth flow
$state = mt_rand();
$client->setState($state);
$_SESSION['state'] = $state;
$authUrl = $client->createAuthUrl();
$htmlBody = << You need to authorize access before proceeding.
END;
}
/**
* Updates a channel's default language and sets its localized metadata.
*
* @param Google_Service_YouTube $youtube YouTube service object.
* @param string $channelId The id parameter specifies the channel ID for the resource
* that is being updated.
* @param string $defaultLanguage The language of the channel's default metadata
* @param string $language The language of the localized metadata
* @param string $description The localized description to be set
* @param $htmlBody - html body.
*/
function setChannelLocalization(Google_Service_YouTube $youtube, $channelId, $defaultLanguage,
$language, $description, &$htmlBody) {
// Call the YouTube Data API's channels.list method to retrieve channels.
$channels = $youtube->channels->listChannels("brandingSettings,localizations", array(
'id' => $channelId
));
// If $channels is empty, the specified channel was not found.
if (empty($channels)) {
$htmlBody .= sprintf('Can\'t find a channel with channel id: %s
', $channelId);
} else {
// Since the request specified a channel ID, the response only
// contains one channel resource.
$updateChannel = $channels[0];
// Modify channel's default language and localizations properties.
// Ensure that a value is set for the resource's snippet.defaultLanguage property.
// To set the snippet.defaultLanguage property for a channel resource,
// you actually need to update the brandingSettings.channel.defaultLanguage property.
$updateChannel['brandingSettings']['channel']['defaultLanguage'] = $defaultLanguage;
$localizations = $updateChannel['localizations'];
if (is_null($localizations)) {
$localizations = array();
}
$localizations[$language] = array('description' => $description);
$updateChannel['localizations'] = $localizations;
// Call the YouTube Data API's channels.update method to update an existing channel.
$channelUpdateResponse = $youtube->channels->update("brandingSettings,localizations",
$updateChannel);
$htmlBody .= "Updated channel
";
$htmlBody .= sprintf('
';
}
}
/**
* Returns localized metadata for a channel in a selected language.
* If the localized text is not available in the requested language,
* this method will return text in the default language.
*
* @param Google_Service_YouTube $youtube YouTube service object.
* @param string $channelId The channelId parameter instructs the API to return the
* localized metadata for the channel specified by the channel id.
* @param string language The language of the localized metadata.
* @param $htmlBody - html body.
*/
function getChannelLocalization(Google_Service_YouTube $youtube, $channelId,
$language, &$htmlBody) {
// Call the YouTube Data API's channels.list method to retrieve channels.
$channels = $youtube->channels->listChannels("snippet", array(
'id' => $channelId,
'hl' => $language
));
// If $channels is empty, the specified channel was not found.
if (empty($channels)) {
$htmlBody .= sprintf('Can\'t find a channel with channel id: %s
', $channelId);
} else {
// Since the request specified a channel ID, the response only
// contains one channel resource.
$localized = $channels[0]["snippet"]["localized"];
$htmlBody .= "Channel
";
$htmlBody .= sprintf('
';
}
}
/**
* Returns a list of localized metadata for a channel.
*
* @param Google_Service_YouTube $youtube YouTube service object.
* @param string $channelId The channelId parameter instructs the API to return the
* localized metadata for the channel specified by the channel id.
* @param $htmlBody - html body.
*/
function listChannelLocalizations(Google_Service_YouTube $youtube, $channelId, &$htmlBody) {
// Call the YouTube Data API's channels.list method to retrieve channels.
$channels = $youtube->channels->listChannels("snippet,localizations", array(
'id' => $channelId
));
// If $channels is empty, the specified channel was not found.
if (empty($channels)) {
$htmlBody .= sprintf('Can\'t find a channel with channel id: %s
', $channelId);
} else {
// Since the request specified a channel ID, the response only
// contains one channel resource.
$localizations = $channels[0]["localizations"];
$htmlBody .= "Channel
";
foreach ($localizations as $language => $localization) {
$htmlBody .= sprintf('
';
}
}
?>