gpt4 book ai didi

perl - 使用 shuttlecloud 获取谷歌联系人

转载 作者:可可西里 更新时间:2023-11-01 17:36:11 28 4
gpt4 key购买 nike

我无法使用 shuttlecloud 获取 google 用户的联系人。我根据 shuttlecloud 和谷歌文档做了一切。我使用基于密码的身份验证(例如 mail.ru)获得了用户与 shuttlecloud 的联系。我创建 url 并将其放入浏览器 https://accounts.google.com/o/oauth2/auth?redirect_uri=http://localhost:80&response_type=code&client_id=my_id.apps.googleusercontent.com&scope=https://www.googleapis.com/auth/contacts.readonly&access_type=offline

我获取代码并复制到脚本:

my $url = 'https://demo.api.shuttlecloud.com/beta/load';
my $auth_url = 'https://demo.api.shuttlecloud.com/beta/auth/capabilities';
my $appid = 'my_shuttlecloud_id';
my $ts = int(time);
my $secret = 'my_shuttlecloud_secret';
my $sig = sha256_hex("{".$appid.":".$secret.":".$ts."}");
my $url_tok = 'https://www.googleapis.com/oauth2/v3/token';
my $code = '4/GmVQi8AgNzajSo0mTudUBumjHyHhhb9EBxN8ufG6z34.QjE7Q6MjmUweWmFiZwPfH01FreiwmwI';
my $id = 'my_google_id';
my $sec = 'my_google_secret';
my $redirect = 'http://localhost:80';
my $grant_type = 'authorization_code';

my $response = $ua->request(POST $url_tok,
Content_Type => 'application/x-www-form-urlencoded',
Content => [ code => $code,
redirect_uri => $redirect,
client_id => $id,
client_secret => $sec,
grant_type => $grant_type,
]);
my $cod = $response->content;
my $decoded_json = decode_json( $cod );
my $token = @{$decoded_json}{'access_token'};
my $email = 'my_google_email@gmail.com';
my $data = '{
"contactsextraction": {
"sourceaccount": {
"userid": {
"email": "'.$email.'"
},
"auth": {
"3loauth": "'.$token.'"
}
}
}
}';

$url = $url."?appid=".$appid."&ts=".$ts."&sig=".$sig;
my $req = HTTP::Request->new(POST => $url);
$req->content($data);
my $resp = $ua->request($req);
my $message;
if ($resp->is_success) {
$message = $resp->decoded_content;
}
else {
print "error code: ", $resp->code, "\n";
print "error message: ", $resp->message, "\n";
}
$decoded_json = decode_json( $message );
my $ft_url = @{$decoded_json}{'fetchurl'};
$ft_url = $ft_url."?appid=".$appid."&ts=".$ts."&sig=".$sig;
sleep 5;
$req = HTTP::Request->new(GET => $ft_url);
$resp = $ua->request($req);
if ($resp->is_success) {
$message = $resp->decoded_content;
}
else {
print "error code: ", $resp->code, "\n";
print "error message: ", $resp->message, "\n";
}
$decoded_json = decode_json( $message );
print Dumper ($decoded_json);

我从 shuttlecloud json 收到:'status' => 'STARTED' 没有联系人。当我使用 OAuth 2.0 Playground 创建 token 并粘贴到脚本时 - 一切正常。由此,我没有正确创建访问 token ,但无法理解我做错了什么。

最佳答案

在文档中说:

This request returns the status of the job and the extracted contacts up to that point in time from the account.

The server provides a URL from which the real-time progress can be retrieved.

您需要进行轮询以检索联系人,直到它们准备就绪。它非常快,通常是几秒钟,但不是即时的。尝试在循环中执行联系人获取请求,例如在每个请求之间等待 1 秒,您应该获得所有联系人。

关于perl - 使用 shuttlecloud 获取谷歌联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30733845/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com