我正在使用 Matt Harris 的 tmhOAuth 库向 Yelp 的 API 生成经过身份验证的请求。我已经在使用同一个库来访问 Twitter API,它运行良好。
我已经注册了 Yelp Developer API 凭证并正在使用它们。
我设置了 tmhOAuth 来发出如下请求:
http://api.yelp.com/v2/search?limit=20&location=Atlanta&term=food
我的预感不知何故我的身份验证凭据没有正确输出,即使你会认为我会从 Yelp 那里得到某种错误。例如,我将我的使用者密钥和秘密以及我的用户令牌和秘密更改为随机字符,但是当我使用这些伪造的密钥发出请求时,我得到与下面相同的响应并且仍然没有身份验证错误消息。根本不值一提!
我确信其他人在第一次设置对 Yelp API 的调用时可能会遇到类似的响应并告诉我一些明显我做错了的事情。任何帮助是极大的赞赏。
我从 Yelp 得到的回复是:
Array (
[headers] => Array (
[date] => Sat, 03 Nov 2012 21:36:15 GMT
[server] => Apache
[x_node] => wsgi, web31, api_com
[content_length] => 0
[cache_control] => max-age=0, must-revalidate, no-cache, no-store, private
[expires] => Sat, 03 Nov 2012 21:36:15 GMT
[pragma] => no-cache [set_cookie] => bse=0aff211810c8d90f05c4e8438a3e0b7b; Domain=.yelp.com; Path=/; HttpOnly
[location] => http://api.yelp.com/v2/search?limit=20&location=Atlanta&term=food
[vary] => User-Agent
[connection] => close
[content_type] => text/html; charset=UTF-8
[x_mode] => rw
[x_proxied] => lb2
)
[code] => 301
[response] =>
[info] => Array (
[url] => https://api.yelp.com/v2/search?limit=20&location=Atlanta&term=food
[content_type] => text/html; charset=UTF-8
[http_code] => 301
[header_size] => 534
[request_size] => 439
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.653941
[namelookup_time] => 0.000981
[connect_time] => 0.073796
[pretransfer_time] => 0.297663
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.653791
[redirect_time] => 0
[certinfo] => Array ( )
[request_header] => GET
/v2/search?limit=20&location=Atlanta&term=food
HTTP/1.1 User-Agent: themattharris' HTTP
Client Host: api.yelp.com Accept: */* Authorization: OAuth
oauth_consumer_key="****************",
oauth_nonce="*******************",
oauth_signature="***************************",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1351978544",
oauth_token="******************",
oauth_version="1.0"
)
)
对于这篇文章,我显然混淆了上面的实际密钥、随机数和签名字符串。