In this tutorial, we'll be talking about how to run the
PHP samples for a YouTube V3 API.
For this to work, you'll need a local installation
of Apache and PHP.
I'm running this demo on OSX, which ships with a version of
Apache with PHP.
To enable PHP, I just have to make a few
configuration changes.
The first thing you want to do is verify that our PHP
installation is working correctly.
You can skip this if you know that it is working correctly.
I'm going to go ahead and create a new PHP file.
I'm going to edit it.
Now I'm going to go ahead and browse to this PHP file.
And I can see that it's working.
So let's go ahead and download the API
client library for PHP.
We can find this at code.google.com/
p/google-API-PHP-client.
We'll click on Download the Latest Release.
While we're doing that, we also want to download the
YouTube API samples.
We can find these at code.google.com/
p/youtube-api-samples.
Click on the download link, and we'll
download the samples.
Once these have downloaded, we should unpack them.
Let's now copy the files into a directory that we'll be
running PHP files off of.
We'll also want to copy the PHP samples over.
Now, let's give it the proper permissions.
I'm recursively giving it 7, 5, 5.
Now let's make the search sample work.
The first thing we'll need to do is call set
include path on our code.
We'll want to include the Google API client library.
We'll also need to set the developer key.
We can find this from the Google API console,
code.google.com/APIs/console.
If you browse there, and you don't see this page, you'll
want to watch a video about how to create and register a
YouTube API key.
Scroll down to Simple API Access.
Let's copy the key.
And let's paste it over the place holder.
Let's save the file and browse through this search sample.
We should see this page.
And when we click Search, we'll see the search results.
The next sample we'll try to get running will be the My
Upload sample.
So let's go ahead and open that up in our text editor.
The sample demonstrates how to use the three legged OAuth 2.0
flow to authorize your script to run on behalf of user.
We'll need to copy over set include path.
We'll also need to set the client ID
and the client secret.
Again, we can find these in the Google API console.
Now let's go ahead and run our code.
Note that this first run will not work yet.
We'll be asked to authorize, and we'll see an error page.
It's because we need to register this URI as a
redirect URI in the API console.
So let's go ahead and copy it, go back to the API console,
click on Edit settings.
We'll paste it into the authorized redirect URI's box.
Let's click update.
Now let's click back and try to run our sample again.
And run the code again.
You'll see that the code is now requesting
that I allow access.
I'll click Allow.
The script is now running.
So that's what you need to run the sample codes for Search
and My Uploads in PHP.