【问题标题】:Youtube API: Resume Upload *User Authentication Required*Youtube API:恢复上传*需要用户验证*
【发布时间】:2013-10-05 01:09:01
【问题描述】:

我很累,三天没有睡觉,我卡在一件事情上, 这个 youtube 上传的东西。

这个非常简单的 POST 过程总是会导致:“需要用户身份验证”

这是我模仿的:

POST /resumable/feeds/api/users/default/uploads HTTP/1.1
Host: uploads.gdata.youtube.com
Authorization: Bearer ACCESS_TOKEN
GData-Version: 2
X-GData-Key: key=adf15ee97731bca89da876c...a8dc
Content-Length: 0
Slug: my_file.mp4

到目前为止,这是我所做的:

#!/usr/bin/perl

use 5.010;
use strict;
use warnings;
use LWP::Simple;


    my $r = LWP::UserAgent->new()->post(
    "https://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads",
        Content_Type => "application/atom+xml; charset=UTF-8",
        [
        'POST /resumable/feeds/api/users/default/uploads HTTP/1.1',
            Host            => "uploads.gdata.youtube.com",
           'Authentication' => "Bearer xxxxxx",
           'GData-Version' => "2",
           'X-GData-Key' => "key=xxxxx",
            Content_Length => "0",
           'Slug' => "C:/YouTube.wmv",
        ]
    );

    say $r->content;

我尝试了所有身份验证、Oath2、clientLogin、 我可以登录并获取access_token,问题是我无法上传,

我喜欢 perl,但我讨厌使用 perl 的 youtube 没有支持库这一事实(有,但是它的非常过时和直接上传功能没有明确记录或者可能根本没有) 请帮助我,我非常需要这个,我真的坚持这个,我不知道是我的问题还是 youtube 的问题。

感谢您花时间阅读本文,非常感谢。

【问题讨论】:

  • 您确定您的身份验证令牌有效吗?即,上传以外的方法是否有效?此外,没有 Perl 的 youtube 库,因为没有人愿意编写和发布一个。在 github 上上传您正在处理的任何内容,然后就可以运行您的代码,查看问题并解决问题。

标签: perl api upload youtube


【解决方案1】:

在我看来,您在调用 post() 时使用了错误的语法。

documentation 不是很清楚,但我认为你想要这样的东西:

my $r = LWP::UserAgent->new()->post(
    'https://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads',
    Content_Type => "application/atom+xml; charset=UTF-8",
    [
        Host            => "uploads.gdata.youtube.com",
       'Authentication' => "Bearer xxxxxx",
       'GData-Version'  => "2",
       'X-GData-Key'    => "key=xxxxx",
        Content_Length  => "0",
       'Slug'           => "C:/YouTube.wmv",
    ]
);

您不需要明确调用POST() 的那一行。 post() 方法可以为您做到这一点。

【讨论】:

    猜你喜欢
    • 2013-08-29
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 2013-04-14
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多