试验 Yelp API PHP

Experimenting with Yelp API PHP

获取错误消息 - 注意:尝试获取 属性 中的非对象 我正在尝试 experiment/learn 使用 [=26] =] API 但我遇到了一条简单的错误消息,我似乎无法弄清楚。接下来:https://github.com/Yelp/yelp-api/tree/master/v2/php

function query_api($term, $location) {     
$response = json_decode(search($term, $location));
$business_id = $response->businesses[0]->id;

print sprintf(
    "%d businesses found, querying business info for the top result \"%s\"\n\n",         
    count($response->businesses),
    $business_id
);

$response = get_business($business_id);

print sprintf("Result for business \"%s\" found:\n", $business_id);
print "$response\n";

}

调用函数

$longopts  = array(
"term::",
"location::",
);

$options = getopt("", $longopts);

$term = $options['term'] ?: '';
$location = $options['location'] ?: '';

query_api($term, $location);   

此通知表明 $response 不是对象,您正在尝试访问不存在的 属性 businesses
使用 var_dump($response) 获取有关此变量的信息。