【发布时间】:2019-02-05 21:23:35
【问题描述】:
我有一个脚本在 v2 上运行良好,但在它过期并转移到 v3 时崩溃了。
我已尝试修复它,但显然还有更多内容,只是将 v2 更改为 v3。显然他们已经弃用了秘密令牌。
这是我目前拥有的:
// Enter the path that the oauth library is in relation to the php file
require_once ('../lib/OAuth.php');
// For example, request business with id 'the-waterboy-sacramento'
$unsigned_url = "https://api.yelp.com/v3/businesses/search?term=niks-italian-kitchen-bar-austin";
// Set your keys here
$consumer_key = "xxxxxxx";
$consumer_secret = "xxxxxxxxx";
$token = "xxxxxxxx";
$token_secret = "xxxxxxxxxxx";
// Token object built using the OAuth library
$token = new OAuthToken($token, $token_secret);
// Consumer object built using the OAuth library
$consumer = new OAuthConsumer($consumer_key, $consumer_secret);
// Yelp uses HMAC SHA1 encoding
$signature_method = new OAuthSignatureMethod_HMAC_SHA1();
// Build OAuth Request using the OAuth PHP library. Uses the consumer and token object created above.
$oauthrequest = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $unsigned_url);
// Sign the request
$oauthrequest->sign_request($signature_method, $consumer, $token);
// Get the signed URL
$signed_url = $oauthrequest->to_url();
echo $signed_url;
// Send Yelp API Call
$ch = curl_init($signed_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch); // Yelp response
curl_close($ch);
// Handle Yelp response data
$response = json_decode($data);
// Print it for debugging
echo '<pre>';
print_r($response);
echo '</pre>';
非常感谢您朝正确的方向轻推。
我收到一个错误:
stdClass Object ([error] => stdClass Object ([code] => TOKEN_MISSING [description] => 必须提供访问令牌才能使用此端点。))
我是否需要为v3 重新生成我的 API 凭据?
【问题讨论】:
-
怎么了?您是否遇到特定错误?
-
是的,我得到:stdClass Object ( [error] => stdClass Object ( [code] => TOKEN_MISSING [description] => 必须提供访问令牌才能使用此端点。 ) ) 我需要为 v3 重新生成我的 API 凭据吗?
-
你能说出错误是在哪一行引发的/什么命令触发它?
标签: php api yelp yelp-fusion-api