YouTube v3 API PHP - Add Playlist Server to Server

Viewed 111

All I want to do, with PHP and google-api-php-client, is create a new playlist and add it to my YouTube Channel server to server. All guides seem to require me manually clicking a link generated to authorize a token. What?!? With an API key shouldn't I just be able to do server to server changes/uploads/edits without any need of human interaction?

I enabled the API, created API Keys and OAuth ID/Secrets, but still can't figure out how to do it.

Any guide would be appreciated. Server to Server, with PHP, without me needing to open the file in a browser to allow access to account.

Thanks

Tried this: https://developers.google.com/youtube/v3/code_samples/php for adding a playlist and can't get it to work, even after clicking the link and allowing access to account.

1 Answers

You want to start learning something called OAuth. Don't worry, it's only sounds scary. I'll try and ease it a bit for you. But before I begin, no amount of loitering around avoiding that OAuth thing is going to get you anywhere. Good news is: it's not that twisted.

Imagine you were YouTube. An application, say a web application someone wrote that you didn't know about were to come to you making an HTTP request on you.

The request were to say, "Hey, YouTube chum! Can you add this bunch of erotica to John's playlist and just make it all public for everyone to see?"

What would be your response?

If I were YouTube, mine would be --

"Yeah! fook you, dude! Go ask John first! Then, show me some proof that you did."

"And wait a second, before you leave, I forgot to ask, who the fook are you, in fact? You got something to show me for who you are?" I, the YouTube, would add.

You see the problem? For YouTube, there are really two parties involved in this transaction:

  1. The application that's making the sleazy request; and

  2. Poor John, who probably knows nothing of all this even when he should.

Otherwise, what's to stop any application asking YouTube (or Facebook or Google or Github or any place else) for John's data?

So, as far as YouTube is concerned, it needs a way for the application to authenticate itself with YouTube (thus the Application Id and Client Secret or App Secret you created on the Google Developer Console), and it needs John's permission to let the said application do what it is asking you (YouTube) to do (thus the need for John to interact with a UI).

Enter OAuth.

OAuth is a document of rules that allows this co-operative transaction. But for it to work, all the three, YouTube, the web application, and John, must first conspire together.

There are three parties in OAuth:

  1. The OAuth server -- that has John's data. In this example, it was YouTube.

  2. The third-party application that wants to do something with John's data that's kept on the OAuth server, i.e. YouTube.

  3. Poor John, a user on the OAuth server (YouTube), and also wanting to use the third-party Web application that wants YouTube to do something with John's data.

Now, there's a whole lot to learn about OAuth before you write a single line of code, and I can't write it all here but here's a YouTube playlist that starts by explaining the very basics of OAuth and then provides demos in (sorry, no PHP) C# and also in JavaScript.

Once you understand the OAuth transaction mechanism and see some code, then re-visit the YouTube API documentation page you linked to and it'll start to make an enormous amount of sense. It'll click and you won't need to look any place for help writing that example. It'll just come out of you like poop. :-)

Related