Tuesday, July 24, 2012

Ported the CI YouTube library to plain old PHP

I finally got around to porting my CodeIgniter YouTube API Library to regular PHP. There honestly aren't that many CI dependencies so it was a fairly easy library to port.

I changed how the constructor is setup so it's a little more descriptive when being instantiated. All of the API calls remained the same so you can checkout the CI library for example calls to make. I included some example code on how to use the API. The example files are index.php and authorize.php they demonstrate how to authenticate with YouTube then make calls. Let me know if you have any issues or questions.

The GitHub repos is: https://github.com/jimdoescode/Zendless-PHP-YouTube-API


  1. I absolutely new to Drupal so I'm still programming presently, in a learning from your errors style. I wish the new edition will be on the internet soon! You can have a look to the current edition for now, just to evaluate it to the new edition when it's done. Remain tuned!

  2. Hi there. I apologize in advance for asking a very basic question.

    I downloaded your API; and, created a Google API project. I'm trying to fill in the key, secret and api key in your index.php and authorize.php files. These are indicated as info google should have provided to me. The Google API project API Access section has sections for:
    - Client ID for web apps (info includes client secret)
    - Service account (info includes public key fingerprints)
    - Simple API Access (info includes API key)

    My question is: how should I fill in the key and secret? The api key seems straightforward.

    Thanks, Ed

    1. Hi Ed,

      Please follow this link it will get you up and running with OAuth 1.0. I should note (and you will notice) google has deprecated this form of authentication and recommends that you use OAuth 2.0 instead. My code only supports 1.0

      Here is the link with more information: https://developers.google.com/accounts/docs/RegistrationForWebAppsAuto

  3. Any plans to upgrade this to OAuth 2.0 ? I want to use your API directly in php as I want to integrate it my custom php and API script but cant do so using code ignitor

    1. You can use OAuth 2.0 with the API. To do so you include your token as a parameter for each method call. However you are responsible for getting the token instead of using the google_oauth library.

  4. Hi JimDoesCode,

    How can I update access token?
    Can I set token expirition time?

    Can you please help with an example code?

    Thanks for your time.

  5. Hello,

    Thanks for your API. It helped me allot.

    I am building an application that can upload videos in background. I did it successfully. But here I have a few doubts. Please help me.

    1. What is the life time of an access token? How can I know it?
    2. How can I get offline access?
    3. If there is no way to get offline access how can I get long lived tokens?

    Please help me.

    Thanks for your time.

    1. 1. It depends on the version of OAuth you are using. If you use 1.0 then the access token lasts forever. If you use 2.0 then there is some time out that you will need to check with google about.

      2. I have no idea what offline access means. I would say you can't since you need to be online to upload videos etc.

      3. See #1.