【问题标题】:Dailymotion API - Can't get to a video to uploadDailymotion API - 无法上传视频
【发布时间】:2020-10-06 01:53:47
【问题描述】:

我无法获取上传 DailyMotion API 的文件。

我正在执行以下步骤:https://developer.dailymotion.com/video-upload/upload-new-video-api/

第一个 API 调用运行良好,并向我返回了“upload_url”,我将它输入到您将在下面看到的方法中。

第二步失败,响应错误为:

{"error":"missing content size","seal": "[some string]"}

我应该如何设置内容大小?

第二次调用的代码:

<?php

namespace PierreMiniggio\YoutubeChannelCloner\Dailymotion\API;

class DailymotionFileUploader
{

    public function upload(string $uploadUrl, string $filePath): ?string
    {
        $formattedFile = function_exists('curl_file_create')
            ? curl_file_create(str_replace('\\', '/', $filePath))
            : sprintf("@%s", $filePath)
        ;

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $uploadUrl);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt(
            $ch,
            CURLOPT_POSTFIELDS,
            ['file' => $formattedFile]
        );
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $response = curl_exec($ch);
        //var_dump($response); die(); // the output I printed above

        curl_close($ch);

        if (empty($response)) {
            return null;
        }
        
        $jsonResponse = json_decode($response, true);

        if (empty($jsonResponse) || ! isset($jsonResponse['url'])) {
            return null;
        }
        
        return $jsonResponse['url'];
    }
}

操作系统:W10 我确保文件路径和上传 URL 正确。

我尝试使用 dailymotion/sdk 库并使用上传文件的函数而不是使用我的 curl 请求,但我得到了完全相同的错误。

【问题讨论】:

  • 如果您正在关注您链接的页面,应该有 3 个 curl 调用,而我在您的代码中只看到 1 个
  • 我发布的代码是第二次调用。第一个是在另一个文件中完成的,没有问题。它为我提供了一个正确的“upload_url”,我将其作为方法参数提供给我发布的代码。

标签: php php-curl dailymotion-api


【解决方案1】:

问题已解决,这是 curl/PHP 的问题。 我在 PHP 7.4.3-dev 中运行脚本,更新到 7.4.11,它解决了这个问题。 有关此错误的更多信息:https://bugs.php.net/bug.php?id=79013

【讨论】:

    猜你喜欢
    • 2014-12-16
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 1970-01-01
    • 2017-09-11
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    相关资源
    最近更新 更多