繁体   English   中英

使用Perl模块LWP :: Authen :: OAuth2创建Google Team Drive

[英]Create Google Team Drive with Perl module LWP::Authen::OAuth2

我试图将Perl与LWP :: Authen :: OAuth2结合使用来执行Google团队驱动器的创建。 了解如何使用Google Drive API创建Google Team Drive,它需要发布1个参数requestId和另一个JSON正文name (参考: https : //developers.google.com/drive/api/v3/reference/teamdrives/create

但是,我不断收到错误代码400和错误消息,

必须提供团队驱动器的名称,不能为空,也不能完全为空格。

表示name的json正文未正确发布。

下面是我的代码:

# Go get the auth tokens
$oauth2->request_tokens(code => $code);

my $requestID = "randomrequestID";
my $json = '{"name": "anyteamdrivename"}';

my $resp = $oauth2->post("https://www.googleapis.com/drive/v3/teamdrives?requestId=$requestID, Content-Type => application/json, Content => $json");


my $data = decode_json($resp->content());
use Data::Dumper;
print Dumper $data;

感谢具有Perl知识的人是否能够遮挡某些光线。

您没有正确将参数传递给->post

my $resp = $oauth2->post("https://www.googleapis.com/drive/v3/teamdrives?requestId=$requestID, Content-Type => application/json, Content => $json");

将所有从Content-Type开头的内容移出字符串:

my $resp = $oauth2->post(
    "https://www.googleapis.com/drive/v3/teamdrives?requestId=$requestID",
    "Content-Type" => "application/json",
    "Content" => $json
);

另请参见->post方法上的LWP :: UserAgent文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM