2013-04-16 70 views
1

我正在尝试使用PHP(不使用客户端API)对PhotoBucket REST API进行第一步验证。 开发者网站因为他们升级服务而关闭,但他们提供给我一个SCID和一个私钥,我认为这是客户密钥和客户机密。 我一直在寻找文档和其他职位没有运气。 https://stackoverflow.com/questions/7890518/register-user-by-php-in-photobucket无法验证PhotoBucket REST API

这里就是我想出迄今:

//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 +?+参数+ &签名=签名我得到: 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

我张贴了这个问题作为最后的手段。但是,我无法想到我终于明白了。

1)的MD5()添加到时间()方法来克服 “验证失败的随机数无效”

2)正确地签署该基底线(使用$ raw_output =真) $符号= BASE64_ENCODE( hash_hmac(“sha1”,$ basestring,secret。“&”,true));使用rawurlencode而不是进行urlencode(尖从feed7.com用户)

4)发送在后URL一切(无后的数据(postfields)的一些文档页面状态),以克服

3)“验证失败时间戳无效“

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

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

+0

我一直收到错误无效的方法100 – PinoyStackOverflower