Using Youtube API, I've created class for my needs. (It works with Zend FW)
class youtube extends html {
var $yt, $user;
public function __construct($user) {
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$this->yt = new Zend_Gdata_YouTube();
$this->yt->setMajorProtocolVersion(2);
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$this->yt->getHttpClient()->setConfig(array('timeout' => 180));
$this->user = $user;
}
}
The problem is, when I use
$this->yt->getuserUploads($this->user)
on other class methods, it gets ALL videos. I want to get 3 last videos of $user. How to do this?
I'm really short on time at the moment otherwise I'd have a go using your code. This might help if you can't work it out or if no one comes back with an answer using your code.
I put together a quick and dirty solution as an answer for someone who wanted to show the thumbnail corresponding to the latest video uploaded to Youtube by a specific user - I coded a simple controller action and view that would display a video thumbnail which was a link to the video itself.
The example can easily be tweaked to show a particular number of videos by changing the
if($i==1) break;
line however there are probably more elegant ways of doing it than the way I did - as I say it was quick and dirty to answer a question.
I used the Zend_Feed_Reader class instead of the Zend_Gdata_YouTube class. In the short term it might help.
Good luck, let me know if this helped.
All the best, Dave :-D
Link to the question with my example
Take a look at:
$query = $yt->newVideoQuery();
$query->maxResults = 3;
$query->orderBy = 'published';
$query->author = 'ThisIsHorosho';
$query->startIndex = 1;
$videoFeed = $yt->getUserUploads(null,$query);
foreach($videoFeed as $videoEntry)
{
echo $videoEntry->getVideoWatchPageUrl() . PHP_EOL;
}
Related
I want to put my fortnite stats on my website HTML/CSS. I find this.
But I don't know php very good, so I need your help. Must I delete this: 'your_api_key' and put : your_api_key without the ' ' ?
And lines like this:
$this->auth = new Fortnite_Auth($this);
$this->challenges = new Fortnite_Challenges($this);
$this->leaderboard = new Fortnite_Leaderboard($this);
$this->items = new Fortnite_Items($this);
$this->news = new Fortnite_News($this);
$this->patchnotes = new Fortnite_PatchNotes($this);
$this->pve = new Fortnite_PVE($this);
$this->status = new Fortnite_Status($this);
$this->weapons = new Fortnite_Weapons($this);
$this->user = new Fortnite_User($this)
Must I modify something?
(here are some informations:
-user_id: 501b9f2dfda34249a2749467513172bf
-username: NoMaD_DEEPonion
-platform: pc
-windows: season 5
)
For all this code, I used xammp server (I hope it's good)
Thank you for your help
You should always quote '' your key/strings. So it would look like:
$api->setKey('123qwerty456');
$api->user->id('NoMaD_DEEPonion');
Please read their documentation. You're supposed to get an API key from them to get started. And you don't have to edit Client.php. You're supposed to include the files instead. Try including Autoloader.php, since it requires the necessary files.
XAMPP is alright for development, but not suitable for production/public. Good luck!
What #sykez wrote.
I personally use https://fortniteapi.com/ to get the data. They also have a sweet POSTMAN page with different requests https://documenter.getpostman.com/view/4499368/RWEjoGqD
At last. I am not really sure that this will be a good project to start learning PHP from. I really suggest that you get to understand the basics of PHP first before you jump into API calls, processing arrays and more.
I want to display Flickr private pictures on a page.
I have an API + Secret.
I use phpFlickr class by Dan Coulter : http://phpflickr.com
I started something with David Walsh post : http://davidwalsh.name/flickr-php
I set the callback URL of my API key to : http://mydomain.com/mydirectory/flickr.php
I have 3 files in my directory :
phpFlickr.php (the class)
start.php (the auth script)
flickr.php (to display pictures)
Here is the content of start.php :
<?php
session_start();
require_once('phpFlickr.php');
$flickr = new phpFlickr('myapikey','myapisecret', true);
if(empty($_GET['frob'])) {
$flickr->auth('read');
}
else {
$flickr->auth_getToken($_GET['frob']);
header('Location: flickr.php');
exit();
}
?>
Here is the content of flickr.php :
<?
require_once('phpFlickr.php');
$flickr = new phpFlickr('myapikey','myapisecret', true);
$f->enableCache("fs", "cache");
$photos = $f->photosets_getPhotos('myPhotoAlbumIdWithPrivatePicturesInIt', 5);
foreach ($photos['photoset']['photo'] as $photo): ?>
<img src="<?= $f->buildPhotoURL($photo, 'square') ?>" /><br />
<? endforeach; ?>
This is the error message I get :
"The Flickr API returned the following error: #1 - Photoset not found"
But when I use : http://www.flickr.com/services/api/explore/flickr.photosets.getPhotos I get results. The photoset exists.
Dan Coulter writes :
"*To authenticate the app to your account to show your private pictures:
This method will allow you to have the app authenticate to one specific account, no matter who views your website. This is useful to display private photos or photosets (among other things).
Note: The method below is a little hard to understand, so I've setup a tool to help you through this:
http://www.phpflickr.com/tools/auth/.
First, you'll have to setup a callback script with Flickr. Once you've done that, edit line 12 of the included getToken.php file to reflect which permissions you'll need for the app. Then browse to the page. Once you've authorized the app with Flickr, it'll send you back to that page which will give you a token which will look something like this:
1234-567890abcdef1234
Go to the file where you are creating an instance of phpFlickr (I suggest an include file) and after you've created it set the token to use:
$f->setToken("[token string]");
This token never expires, so you don't have to worry about having to login periodically.*"
Therefore, I think I have an authentication problem. Which would explain that the photoset "doesn't exist".
But where am I wrong ?
Is there a way to make it simpler in 1 script instead of 2 ?
Thank you in advance for your help.
Hey almost 2 years ago myself...
Anyway.
I found a solution a bit later after the question and never posted a reply. I think it could be interesting, even if late, for other people :
So, pretty sure there is something smarter to do but I didn't find it. I found "a way" to do what I needed.
I needed to make a private web page with galeries of private photos.
<?php
require_once("phpFlickr.php");
$f = new phpFlickr('myapikey','myapisecret');
$f->enableCache("fs", "cache");
//This is what I really missed: the token number.
$f->setToken('myratherlongtoken-number');
//Dan Coulter explains it in the documentation of phpFlickr
//He also provides a tool to ask a token.
$username="My Username";
$result = $f->people_findByUsername($username);
$nsid = $result["id"];
?>
//After, you can display infos of your private album (knowing its ID)
//Such as primary photoset image, total number of photos...
<?php $infos = $f->photosets_getInfo('12345MyAlbumId67890'); ?>
//Or even process a loop to display a gallery
<?php $photos = $f->photosets_getPhotos('12345MyAlbumId67890','','5');
foreach ($photos['photoset']['photo'] as $photo): ?>
I want to control the access in php website.
I have a solution right now with switch case.
<?php
$obj = $_GET['obj'];
switch ($obj)
{
case a:
include ('a.php');
break;
default:
include ('f.php');
}
?>
But when i have so many pages, it becomes difficult to manage them. Do you have better solutions?
Right now, i develop the application using php4. And i want to use php5. Do you have any suggestions when i develop it using php5?
Thanks
$obj = $_GET['obj'];
$validArray = array('a','b','c','d','e');
if (in_array($obj,$validArray)) {
include ($obj.'.php');
} else {
include ('f.php');
}
The more pages you have the harder it will be to control this.
Your best off using a framework of some sort, my personal preference is CodeIgniter.
why not just address a page itself?
first page
another page
I am not saying that this is the best solution, but years ago I used to have a website which used a database to manage the key, the page to be included, and some informations like additional css for instance.
So the code was something like:
<?php
$page = htmlspecialchars($_GET['page']);
$stuffs = $db->query('select include,css from pages where pageid = "' . $page . '" LIMIT 1');
?>
So when we needed to add a page, we just created a new field in the database. That let us close a part of the website too: we could have a "available = {0,1}" field, and if zero, display a static page saying that this page was under maintenance.
is any method to validate Youtube video link with Zend-framework ?
If user inputs not valid link, for example http://www.youtube.com/watch?00zzv=nel how can I check it before inserting into site ?
I'm pretty sure that there is no built in validator for this, but writing custom validators is super easy:
class My_Validate_Youtube extends Zend_Validate_Abstract{
public function isValid($value){
// check url here
if (no_good($value)){
$this->_error("Explain the error here");
return false;
}
return true;
}
}
Just put whatever checks you need in that class, and run the validator on any Youtube links to be checked.
edit:
From Laykes, you might want to consider using the validator to check if the video actually exists, instead of determining if it fits a pattern. Depends on your use cases though- eg how much latency do you want to introduce by making a call to the Youtube API?
I don't know if it is possible, however, I would take a different approach and try and see if the link has comments on it.
Take this for example. From here:
http://framework.zend.com/manual/en/zend.gdata.youtube.html
$yt = new Zend_Gdata_YouTube();
$commentFeed = $yt->getVideoCommentFeed('abc123813abc');
foreach ($commentFeed as $commentEntry) {
echo $commentEntry->title->text . "\n";
echo $commentEntry->content->text . "\n\n\n";
}
If you use the video id in the VideoCommentFeed argument, you will be able to get the value in $commentFeed. If you then get an error, you know that the video does not exist.
I am sure if you try other methods you will probably find example what you want.
Hey guys, I'm using Twitter's PHP API, called twitterlibphp, and it works well, but there's one thing that I need to be able to initiate, which is the linking of URLs and #username replies. I already have the function for this written up correctly (it is called clickable_link($text);) and have tested it successfully. I am not too familiar with parts of twitterlibphp (link goes to source code), and I am not sure where to put the function clickable_link() in order to make URLs and #username's clickable. I hope that is enough information, thanks a lot.
EDIT:
In addition, I would like only one status to come up in the function GetFriendsTimeline(), right now 20 come up, is there any easy way to limit it to one?
I would extend the Twitter class and put the functionality in my own getUserTimeline method.
class MyTwitter extends Twitter
{
public function getUserTimeline()
{
$result = parent::getUserTimeline();
// Your functionality ...
return $result;
}
}
You don't need to put clickable_link() in twitterlibphp. Instead, call it right before you output a status message. Example:
$twitter = new Twitter('username', 'password');
$result = $twitter->getUserTimeline();
... parse the $result XML here ...
echo 'Status : '.clickable_link($status);