duanlu0386 2016-06-27 04:51
浏览 49

Php:Api返回错误请求错误消息

I am trying to get list of videos using youtube apiv3, but i will get a bad request if publishedAfter parameter present in the request.

According to their documenation

Type: datetime

The publishedAfter parameter indicates that the API response should only contain resources created after the specified time. The value is an RFC 3339 formatted date-time value (1970-01-01T00:00:00Z).

So i convert the date parameter to RFC3339 format Here is my code

    $time="2016-06-21 05:40:00";
    $datetime = \DateTime::createFromFormat("Y-m-d H:i:s", $time);
    //RFC3339 format
    echo $t=(datetime)$datetime->format(\DateTime::RFC3339);

Here is the url for getting result

 $url='https://www.googleapis.com/youtube/v3/search?part=snippet&order=viewCount&key={kEY}&&publishedAfter='.$t;

I will get this error

Array
(
    [error] => Array
        (
            [errors] => Array
                (
                    [0] => Array
                        (
                            [domain] => global
                            [reason] => badRequest
                            [message] => Bad Request
                        )

                )

            [code] => 400
            [message] => Bad Request
        )

)

Note:

Without publishedAfter parameter i will get response, so i think the problem with dateformat.

  • 写回答

1条回答 默认 最新

  • douhuiwan5141 2016-06-27 05:44
    关注

    Please try something below.

    $time="2016-06-21 05:40:00";
        $datetime = new DateTime($time);
        $datetime->format('Y-m-d\TH:i:sP');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思