Jim Miller
Jim Miller

Reputation: 3329

YouTube API v3 call works in browser, fails in code

I'm trying to make a call from PHP to the YouTube API v3 to get the duration of a video. I've got my developer key, and have assembled what seems to be a valid URL, based on Google's docs and many other posts on SO:

https://www.googleapis.com/youtube/v3/videos?id=rpVJkH7dWsY&part=contentDetails&key={myDeveloperKey}

I can enter this url into a browser, and a correct hunk of stuff comes back. But when I call it from PHP via file_get_contents($the_url), it fails with a "Connection timed out" error.

I must be doing something wrong; any advice? Thanks!

Upvotes: 0

Views: 260

Answers (1)

DynamicFX
DynamicFX

Reputation: 46

I'm doing it the exact same way you're describing, with file_get_contents($the_url), and it works fine for me. The only thing I can think of if it works in a browser but not on your server, is to make sure you're using a different API key that's a server key, where you'd be using a browser key to test from your browser, presumably. If that's not the issue, I can't think of any other obvious reason it shouldn't work.

Upvotes: 1

Related Questions