无法验证PhotoBucket REST API

时间:2013-04-16 15:29:58

标签: php api rest photobucket

我正在尝试使用PHP对PhotoBucket REST API进行第一步认证(不使用客户端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,异常身份验证失败签名检查失败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

1 个答案:

答案 0 :(得分:1)

我发布这个问题作为最后的手段。 然而,从无到有,我想我终于明白了。

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

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

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

4)发送帖子网址中的所有内容(没有帖子数据(postfields)作为一些文档页面状态)要克服 “身份验证失败时间戳无效”

5)最后,这是这篇文章的主要原因:不要将format参数添加到参数列表的末尾。要么将其删除,要么将其添加到参数列表的前缀中以克服 “身份验证失败签名检查失败”

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