Using MODx Evo 1.0.9. I am trying to use the following snippet to fetch youtube video title in a template:
<?php
$code = "<<<Youtube Video ID>>>";
$video_feed = file_get_contents("http://gdata.youtube.com/feeds/api/videos?v=2&q=".$code."&max-results=1&fields=entry(title)&prettyprint=true");
$video_obj = simplexml_load_string($video_feed);
$video_str = $video_obj->entry->title;
$output = $video_str;
return $output;
?>
In the above code, I want to pass the youtube video ID from a TV in the $code variable. Using [*youtubeID*] does not work. What could be the workaround?
if it works anything like Revo then the youtube id is available as the variable that you passed or as a scriptPrperty,
[[!MySnippetName? &youTubeId='456']]
then in your snippet:
<?php
$code = $youTubeId;
//or
$code = $scriptPropertes('youTubeId);//might have to check this one.
Related
I am using the Youtube data API and I needed to know if there is any way of finding that the youtube channel is a Verified one.
just ran into this today, and while the channelBranding of the V3 youtube API looks promising, I couldn't get it to return if the account/channel user id was verified or not
so I threw up a pretty lame php script that uses DOM model searching to examine the html directly.
to return true if the following element is present.
<a href="//support.google.com/youtube/bin/answer.py?answer=3046484&hl=en" class="qualified-channel-title-badge" target="_blank">
As of today (9/8/2014) a verified user will return true..
<?php
function isVerified($youtubeUser)
{
$youtubeUser = trim($youtubeUser);
$url = '\''."https://www.youtube.com/user/".$youtubeUser.'\'';
$url = "https://www.youtube.com/user/".$youtubeUser ;
$Verified = false;
echo "<BR>looking at $url ";
$ch = curl_init();
$timeout = 10;
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
curl_close($ch);
$dom = new DOMDocument;
#$dom->loadHTML($html);
foreach ( $dom->getElementsByTagName('a') as $link ) {
$myVar = $link->getAttribute('class');
$search = "qualified-channel-title-badge";
$found=false;
$found = strpos($myVar, $search);
if ( $found !== false) {
$Verified = true; //echo "<BR><font color=green>TRUE</font>";
} else {
$Verified = false; //echo "<BR><font color=red>FALSE</font>";
}
}
if ( $Verified ) {
return true;
} else {
return false;
}
}
?>
Bye for now!
RE: mpgn's solution, note that there's a distinction between whether the G+ account is Verified and whether one or more of the accounts YouTube channels are Verified. It's possible for an account to have more than one channel, and each of those channels are verified independently, and for channels to be unverified even though the associated G+ account is verified.
As #Paul Blakely suggests, the current best way to do this is to check the status.longUploadStatus flag, per https://developers.google.com/youtube/v3/docs/channels
As of November, 2022, the YouTube Data API provides no method for determining whether or not a given YouTube channel is or is not verified. Instead, the current approach that yields reliable results is to scrape the channel, and parse a bit of JSON, and search the resulting structure.
We'll start by loading the server response for a given channel. Below I have a channel ID hard-coded in as the id variable:
const id = 'UCFNTTISby1c_H-rm5Ww5rZg';
const response = await needle( 'get', `https://www.youtube.com/channel/${id}` );
With our response object, we should now proceed to check that a 200 OK was received, indicating there were no issues retrieving the page data, and that it is safe to proceed:
if ( response.statusCode === 200 ) {
// proceed to search for verification status
}
Within the block following the condition is where we can start to retrieve the initial data for the YouTube page. When serving a channel page, YouTube will also serve initial data for the channel itself, presumably to speed up delivery among other reasons.
We'll look for this initial data, parse it as JSON, and sift through the results:
const json = response.body.match( /ytInitialData = (.*?);<\/script>/ )[1];
const parsed = JSON.parse( json );
With our data parsed, we'll turn our attention now to one piece of the resulting structure, the c4TabbedHeaderRenderer property. This is where badges for the page (such as a verification badge) are stored. We'll also define a verifiedLabel, to explain what it is we're seeking:
const header = parsed.header.c4TabbedHeaderRenderer;
const verifiedLabel = 'BADGE_STYLE_TYPE_VERIFIED';
Lastly we need to confirm that badges is an array (it may not be, in the event the channel has no badges to enumerate), and follow that up with a check for our verifiedLabel badge:
const verified = Array.isArray(header.badges) && header.badges.some( badge => {
return badge.metadataBadgeRenderer.style === verifiedLabel
});
At this point, verified is either true (if the channel is verified), or false. I hope this helps!
On verified channels, the class "has-badge" is present.
Work in 2018:
<?php
$key = 'has-badge';
$channel = file_get_contents('https://www.youtube.com/...');
if( stripos($channel, $key) !== FALSE )
echo "Verified";
else
echo "Not Verified";
?>
If may be possible to check infer the verified status of a youtube channel via the status.longUploadsStatus flag being either allowed or eligible, as currently this feature requires the associated youtube account to be verified.
source : https://developers.google.com/youtube/v3/docs/channels
I like DigDig plugin but only thing what I would like to change is to have shorter URL in tweets(not some .ly shortner) but to use example.com/?p=123 instead of example.com/2013/../../... I did that on my autoposting tweets plugin it is working perfectly but I can not make it working on this plugin.
This code is constucting URL
public function constructURL($url, $title,$button, $postId, $globalcfg = ''){
if($this->isEncodeRequired){
$title = rawurlencode($title);
$url = rawurlencode($url);
}
$twitter_source = '';
if($globalcfg!=''){
$twitter_source = $globalcfg[DD_GLOBAL_TWITTER_OPTION][DD_GLOBAL_TWITTER_OPTION_SOURCE];
}
//format twitter source
$this->baseURL = str_replace(self::VOTE_SOURCE,$twitter_source,$this->baseURL);
$this->constructNormalURL($url, $title,$button, $postId);
I want that URL to look like this $url = 'example.com/?p=' . $postId; But when I enter this code it is not showing any link.
This code is function of button in frontend
function dd_twitter_generate($buttonDesign='Normal', $source=''){
$post_data = dd_getPostData();
global $globalcfg;
$globalcfg[DD_GLOBAL_TWITTER_OPTION][DD_GLOBAL_TWITTER_OPTION_SOURCE] = $source;
$dd_twitter = new DD_Twitter();
$dd_twitter->constructURL($post_data['link'],$post_data['title'],$buttonDesign,$post_data['id'],false,$globalcfg);
echo $dd_twitter->finalURL;
}
String atomXml = "<?xml version='1.0'?>" +
"<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' gd:fields='yt:accessControl' xmlns:yt='http://gdata.youtube.com/schemas/2007'>" +
"<yt:accessControl action='comment' permission='denied'/>"+
"<yt:accessControl action='rate' permission='denied'/></entry>";
System.out.println("Dsiabling Comments and Rating");
GDataRequest request = service.createPatchRequest(new URL(entry.getEditLink().getHref()));
request.getRequestStream().write(atomXml.getBytes("UTF-8"));
request.execute();
System.out.println("Dsiabling Comments and Rating COMPLETED");
In the above code entry is a VideoEntry which was retuned by uploading a video to YouTube. But when I try the code it throws a null pointer exception. Any fix for this. And If there is any other way of setting the comments and rating disabled its fine as well. I do the following once the Video is published.
String updateUrl = "https://gdata.youtube.com/feeds/api/users/default/uploads/"+videoId;
VideoEntry _entry = service.getEntry(new URL(updateUrl), VideoEntry.class);
VideoEntry vToDel = service.getEntry(new URL(_entry.getEditLink().getHref()), VideoEntry.class);
vToDel.delete();
If you want to delete or update a video you cannot take it directly from edit link of the uploaded VideoEntry. You need to query for a new video entry using the same video id. And use that to update or delete.
I'm using an old version of symfony 1.0.11
slot('breadcrumbs');
include_component('page','breadcrumbs',array('past_pages'=>array(
'/module/action/parameter/value'=>'Home ')));
end_slot();
The problem with this code is that parameter and value do not get passed, so If i click on home i get /module/action but the parameters are not being passed. Any suggestions?
Thanks.
There is also a way automatically set the breadcrumbs this is in the breadcrumbs actions:
// Get the full path without get parameters
$fullPath = $request->getPathInfo();
// get the get parameters
$urlParams = $request->getGetParameters();
// set get parameters as string for url
$this->extend = "";
foreach ($urlParams as $key => $urlParam) {
if (empty($this->extend)) {
$this->extend = "?";
}
this->extend .= $key."=".$urlParam;
}
// Get the URL path and Explode by /
$paths = explode('/', $fullPath);;
$this->paths = $paths;
then in the component itself, you can foreach through the paths and if empty just continue. And always give the GET variables with the link if the browser has some.
Home
<?php foreach($paths as $path):
if(empty($path))
continue;
if(empty($fullPath))
$fullPath = "";
$fullPath .= "/".$path.$extend;
$path = str_replace("-", " ", $path);
?>
<?php if(key($paths->getRawValue()) != (count($paths)-1)): ?>
<?php echo ucwords($path); ?>
<?php else: ?>
<span><?php echo ucwords($path); ?></span>
<?php endif; ?>
This way you never have to set your breadcrumbs if you have a correct url structure.
the way i fixed it is
include_component('page','breadcrumbs',array('past_pages'=>array(
'/module/action?parameter=value'=>'Home ')));
Is there a way to get the list of retweeters ids using streaming api
REST api has "GET statuses/:id/retweeted_by/ids" for getting the list of retweeters
Streaming api has a "statuses/retweet", but is not a generally available resources.
So the idea is to use "statuses/filter" and filter based on tweet ids.
Thank you
In the results returned by the streaming API, retweeters (if any) are listed here:
$retweeters = $tweet->{'retweeted_status'}->{'activities'}->{'retweeters'};
Here's a page which shows the ids of retweeters for a stream filtered with a search for the word 'love' — make sure to use your Twitter username and password. Note that the APIs only return the first 100 retweeters.
<html><body>
<?php
echo(str_pad("START<br>",2048));
#ob_flush();
flush();
$opts = array(
'http'=>array(
'method' => "POST",
'content' => 'track=love',
'header' => "Content-Type: application/x-www-form-urlencoded\r\n"
)
);
$context = stream_context_create($opts);
$username = 'your_twitter_username';
$password = 'your_twitter_password';
while (1){
$instream = fopen('http://'.$username.':'.$password.'#stream.twitter.com/1/statuses/filter.json','r' ,false, $context);
while(! feof($instream)) {
if(! ($line = stream_get_line($instream, 20000, "\n"))) {
continue;
}else{
$tweet = json_decode($line);
$retweeters = array();
$retweeters = $tweet->{'retweeted_status'}->{'activities'}->{'retweeters'};
//We store the new post in the database, to be able to read it later
if (sizeof($retweeters) > 0) {
echo("<br><br>");
print_r($retweeters);
}
#ob_flush();
flush();
}
}
}
?>
</html></body>