Ben
Ben

Reputation: 4452

PHP youtube api error

How to upload videos using youtube api from localhost web application in codeigniter or php?

I followed the steps in youtube library as follows:

 api key : 'my developer key'

 consumer key : 'anonymous' 

 consumer secret : 'anonymous'

I am using the functions as follows and my site url is : http://localhost/ci-youtube/example/request_youtube

//CALL THIS METHOD FIRST BY GOING TO
    //www.your_url.com/index.php/request_youtube
    public function request_youtube()
    {   
        $params['key'] = 'anonymous';
        $params['secret'] = 'anonymous';
        $params['algorithm'] = 'HMAC-SHA1';

        $this->load->library('google_oauth', $params);

        $data = $this->google_oauth->get_request_token(site_url('example/access_youtube'));
        print_r($data);
        $this->session->set_userdata('token_secret', $data['token_secret']);
        redirect($data['redirect']); 
        //$this->load->view('welcome_message');

    }

    //This method will be redirected to automatically
    //once the user approves access of your application
    public function access_youtube()
    {
        $params['key'] = 'anonymous';
        $params['secret'] = 'anonymous';
        $params['algorithm'] = 'HMAC-SHA1';

        $this->load->library('google_oauth', $params);

        $oauth = $this->google_oauth->get_access_token(false, $this->session->userdata('token_secret'));

        $this->session->set_userdata('oauth_token', $oauth['oauth_token']);
        $this->session->set_userdata('oauth_token_secret', $oauth['oauth_token_secret']);
    }

But it shows the error : 'Invalid Token'

Any idea ?

Thanks in advance for quick reply.

Upvotes: 1

Views: 618

Answers (4)

searching9x
searching9x

Reputation: 1605

Timestamp is too far from current time:

It seems like your server time is not correctly set. Please correct your server time, you may want to restart your web server after fixing the time. - Change Server time. Try restart Webserver first. If not work, restart your Computer ==> it work!.

Upvotes: 0

Jim S.
Jim S.

Reputation: 1160

First make sure you are using the correct consumer key and consumer secret.

Second if you run into problems with either the Google_oauth library or the Youtube library make sure you set the DEBUG constant in those libraries to true. Doing that will dump a lot more logging information in to the PHP error log which should help you diagnose the problem.

Upvotes: 0

safrazik
safrazik

Reputation: 1601

I think you still haven't got an API key from YouTube yet. Is that so?

Upvotes: 2

Danack
Danack

Reputation: 25701

I haven't published this yet but I'm about to release a PHP based Youtube autouploader, that allows you to run uploads from a NAS box, spare PC etc.

https://github.com/Danack/Youtube-Autouploader

It has a complete example for how to upload videos to Youtube in there, in particular the function "uploadVideo($filename, $videoInfo)"

https://github.com/Danack/Youtube-Autouploader/blob/master/youtubeCurl.php

Upvotes: 0

Related Questions