【问题标题】:Not able to authenticate PhotoBucket REST API无法验证 PhotoBucket REST API
【发布时间】:2013-04-09 02:17:19
【问题描述】:

我正在尝试使用 PHP(不使用客户端 API)对 PhotoBucket REST API 进行第一步身份验证。 由于他们正在升级服务,开发人员站点已关闭,但他们为我提供了一个 SCID 和一个私钥,我认为这是客户密钥和客户密码。 我一直在寻找文档和其他帖子,但没有运气。 https://stackoverflow.com/questions/7890518/register-user-by-php-in-photobucket

这是我到目前为止的想法:

//default parameters
$url = "http://api.photobucket.com/login/request";
$parameters = array(
        'oauth_consumer_key' => rawurlencode('**key**'),
        'oauth_nonce' => rawurlencode(md5(time())),//no md5, "Authentication failed nonce invalid"
        'oauth_signature_method' => rawurlencode('HMAC-SHA1'),
        'oauth_timestamp' => rawurlencode(time()),
        'oauth_version' => rawurlencode('1.0'),
        'format' => 'json'
    );

//creation of base string and signature
$basestring = rawurlencode("POST") . '&' . rawurlencode($url) . '&' . rawurlencode(http_build_query($parameters));

$sign = base64_encode(hash_hmac("sha1", $basestring, "**secret**" . "&", true));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . "?" . http_build_query($parameters) . '&oauth_signature=' . rawurlencode($sign));
$result = curl_exec($ch);

如果我将参数添加为 POSTFIELDS,我会得到: 401,异常身份验证失败时间戳无效-1366125875 7 xml POST 1366125875

如果我添加示例中的参数 (url + ? + parameters + &signature=signature 我得到: 401, Exception Authentication failed 签名检查失败 7 xml POST 1366125970

参考资料: http://pic.photobucket.com/dev_help/WebHelpPublic/Content/Getting%20Started/Consumer%20Authentication.htm

http://feed7.com/ad-202021/Photobucket-Developer-Forum-Code-Examples-and-Libraries

【问题讨论】:

    标签: php api rest photobucket


    【解决方案1】:

    我发布了这个问题作为最后的手段。 但是,我想我终于想通了。

    1) 将 md5() 添加到 time() 方法中以克服 "身份验证失败 nonce 无效"

    2) 正确签署基本字符串(使用 $raw_output=true) $sign = base64_encode(hash_hmac("sha1", $basestring, secret . "&", true));

    3) 使用 rawurlencode 而不是 urlencode(来自 feed7.com 用户的提示)

    4) 发送帖子 url 中的所有内容(如某些文档页面所述,没有帖子数据(postfields))以克服 "身份验证失败时间戳无效"

    5) 最后,这是这篇文章的主要原因:不要将格式参数添加到参数列表的末尾。要么删除它,要么将其添加到参数列表的开头以克服 "身份验证失败签名检查失败"

    这是因为 Photobucket 强制执行他们所谓的“按名称按字典顺序对参数进行排序”,这意味着参数需要严格按字母顺序排列

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-16
      • 2014-05-04
      • 2014-11-28
      • 1970-01-01
      • 2016-04-18
      • 2017-09-04
      相关资源
      最近更新 更多