【问题标题】:Google Latitude and OAuth Signed requests谷歌纵横和 OAuth 签名请求
【发布时间】:2011-05-25 09:20:37
【问题描述】:

我编写了一个脚本,使用Net::OAuth 对 Google 的纬度 OAuth API 进行身份验证。它正确地进行了身份验证(因为我可以成功地从 API 中获取数据)。但是,当我尝试add an historical entry 时,我得到了401 Unknown authorization header 响应。我正在使用以下代码:

my $location_data = $json->encode(\%data);

$request = Net::OAuth->request("protected resource")->new(
    consumer_key => $c_key,
    consumer_secret => $c_secret,
    token => $token,
    token_secret => $token_secret,
    verifier => $verifier,
    request_url => 'https://www.googleapis.com/latitude/v1/location',
    request_method => 'POST',
    signature_method => $s_method,
    timestamp => time,
    nonce => &nonce(),
    extra_params => {
        key => $s_key
    }
);

$request->sign;

$ua->default_header("Authorization", $request->to_authorization_header);
$ua->default_header("Content-Type", "application/json");

my $res = $ua->post('https://www.googleapis.com/latitude/v1/location?key=' . $s_key,
    Content => $location_data);

所有变量都在 API 的 fetch 部分中使用,所以我知道这些都可以。我不确定我是否使用了正确的 URL 来发帖,我已经尝试了上面示例中的内容以及 $request->to_url

任何建议将不胜感激。

【问题讨论】:

    标签: perl oauth google-latitude


    【解决方案1】:

    在与 Latitude API 团队反复讨论后,确定此错误来自 Content-Type 实际上并未设置为 application/json。把上面的代码改成:

    $ua->default_header("Authorization", $request->to_authorization_header);
    
    my $res = $ua->post('https://www.googleapis.com/latitude/v1/location?key=' . $s_key,
        'Content-Type' => 'application/json',
        Content => $location_data);
    

    一切都按预期进行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-09
      • 2013-07-12
      • 1970-01-01
      • 2015-04-01
      • 2011-01-09
      • 2015-11-01
      • 2015-05-17
      • 2012-07-31
      相关资源
      最近更新 更多