dongtang1944 2016-02-13 16:33
浏览 25
已采纳

YouTube API v3调用在浏览器中运行,代码失败

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!

  • 写回答

1条回答 默认 最新

  • dqlhsm9820 2016-02-15 07:33
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line