【问题标题】:How to get reviews in Bright Local API如何在 Bright Local API 中获得评论
【发布时间】:2015-02-25 09:15:42
【问题描述】:

我正在开发 Bright Local API (https://tools.brightlocal.com/),以获取来自 Yelp、Google+ 等的商家评论。 我从 GitHub 获得了这个 API 的一些代码和一些示例。所以我只需在 Bright Local 中注册一个免费帐户并尝试这些示例以获得评论。

以下代码用于获取某些业务的评论。运行此代码后,我得到了一个工作 ID。但我不知道如何使用此工作 ID 获取评论。

$profileUrls = array(
    'https://plus.google.com/114222978585544488148/about?hl=en',
    'https://plus.google.com/117313296997732479889/about?hl=en',
    'https://plus.google.com/111550668382222753542/about?hl=en'
);

// setup API wrappers
$api = new Api(API_KEY, API_SECRET, API_ENDPOINT);
$batchApi = new BatchApi($api);

// Step 1: Create a new batch
$batchId = $batchApi->create();

if ($batchId) {
    printf('Created batch ID %d%s', $batchId, PHP_EOL);

    // Step 2: Add review lookup jobs to batch
    foreach ($profileUrls as $profileUrl) {
        $result = $api->call('/v4/ld/fetch-reviews', array(
            'batch-id'    => $batchId,
            'profile-url' => $profileUrl,
            'country'     => 'USA'
        ));
        if ($result['success']) {
            printf('Added job with ID %d%s', $result['job-id'], PHP_EOL);
        }
    }

    // Step 3: Commit batch (to signal all jobs added, processing starts)
    if ($batchApi->commit($batchId)) {
        echo 'Committed batch successfully.'.PHP_EOL;
    }
}

有人知道如何使用此 API 获得评论吗?

提前致谢。

【问题讨论】:

    标签: php google-plus review yelp


    【解决方案1】:

    您似乎错过了最后一步,即轮询结果。我们的系统通过将作业添加到队列中然后并行处理这些作业来工作。创建批次、向该批次添加作业并提交后,您需要设置一个循环,或者定期返回并检查结果,直到您看到该批次被标记为“已完成”并且所有作业都已返回数据。

    要执行此调用:

    $results = $batchApi->get_results($batchId); // repeat this call until complete
    

    $results 将包含“状态”,一旦所有作业完成处理以及与每个作业相关的实际结果,该状态将被标记为“已完成”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-28
      • 1970-01-01
      相关资源
      最近更新 更多